Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Creating keyboard shortcuts on the command line Apps
Like most preferences, keyboard shortcuts can be set using "defaults write" commands in the Terminal. Useful if you have lots of shortcuts that you want to define, or if you have more than one Mac to set up.

However, the syntax isn't quite the same as the usual commands for setting a key to a value.

For Application-specific commands, use the following:

defaults write com.developer.app NSUserKeyEquivalents -dict-add "Menu Item" -string "@$~^k"

The meta-keys are set as @ for Command, $ for Shift, ~ for Alt and ^ for Ctrl. k in this example is the non-meta-key that you want to use.

For system-wide shortcuts, you can use -g instead of the app identifier, e.g.

defaults write -g NSUserKeyEquivalents -dict-add "Menu Item" -string "@$~^k" Note that you'll need to relaunch the app before these will take effect. Also you can see if they've been successful in System Preferences -- which will also need a relaunch to show the changes.

    •    
  • Currently 3.73 / 5
  You rated: 2 / 5 (11 votes cast)
 
[9,822 views]  

Creating keyboard shortcuts on the command line | 2 comments | Create New Account
Click here to return to the 'Creating keyboard shortcuts on the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Creating keyboard shortcuts on the command line
Authored by: benwiggy on Nov 26, '13 06:53:05AM

Should this be tagged "Applications"?



[ Reply to This | # ]
Creating keyboard shortcuts on the command line
Authored by: Lri on Apr 07, '14 04:37:01PM

I use a shell script like this to configure the keyboard shortcuts:

defaults write -g NSUserKeyEquivalents '{
"Minimize"="\u200b";
"Minimize All"="\u200b";
}'

defaults write com.apple.finder NSUserKeyEquivalents '{
"Show Package Contents"="@\r";
"Tags..."="@t";
}'

defaults write -app Safari NSUserKeyEquivalents '{
"Show Previous Tab"="@j";
"Show Next Tab"="@k";
"Mail Contents of This Page"="\u200b";
}'

defaults write -app Mail NSUserKeyEquivalents '{
"\033Format\033Indentation\033Decrease"="^\Uf702";
"\033Format\033Indentation\033Increase"="^\Uf703";
}'

The shortcut strings use the same format as in DefaultKeyBinding.dict. For example \Uf702 is the left arrow key.

-app doesn't work with some applications like Finder or Notes.

You can disable a shortcut by assigning the menu item to for example \u200b (ZERO WIDTH SPACE). nil would be triggered by n in some applications like Audacity, \0 would be triggered by any key in Safari in 10.9, and \1 would be triggered by the home key.

If you specify a menu item as Format->Indentation->Increase in System Preferences, it is stored as \033Format\033Indentation\033Increase.



[ Reply to This | # ]