Sometimes when you type a command in Terminal, you need to enter Unicode characters in a parameter string, for example with the defaults command. If you type them in directly (with some Option-key shortcut or using the Character Palette), a sequence of numbers and backslashes will be displayed (the octal notation for the UTF8 encoding of the Unicode character). Often this works OK directly on the command line, but not from within a shell script.
A way to solve this problem is to use the form $'string' (in a bash script). For example, to enter the ellipsis character in the definition of a menu shortcut:
A way to solve this problem is to use the form $'string' (in a bash script). For example, to enter the ellipsis character in the definition of a menu shortcut:
$ defaults write com.apple.iTunes NSUserKeyEquivalents \
$'Subscribe to Podcast342200246' "@S"
Or to enter up and down arrows:
$ defaults write com.apple.Safari NSUserKeyEquivalents \
-dict-add "Select Previous Tab" $'@342206223' # Option+Up
$ defaults write com.apple.Safari NSUserKeyEquivalents \
-dict-add "Select Next Tab" $'@342206221' # Option+Down
I don't understand what causes the different behaviour in shell scripts, but this seems to work both on the command line and in shell scripts. I think this also answers Rob's unanswered question at the end of the Fix iChat's iTunes status message format hint. The string 342231253 in that hint is the octal notation for the UTF8 encoding of Unicode character U266B: "Beamed eighth notes."
•
[9,901 views]

