9

Is there a way to save my custom keyboard shortcuts in a config file?

The reason i want this is so i can put that config file in the cloud (using git, dropbox, ...) and link this file on each os x computer that i have so my shortcuts are always the save on each computer.

4

I use a shell script like this:

defaults write -g NSUserKeyEquivalents '{
"Show in Finder"="$@r";
"Reveal"="$@r";
"Use Selection for Find"="@e";
"Find and Replace..."="~@f";
"Find Next"="@g";
"Find Previous"="$@g";
"Line Spacing..."="~@l";
"Zoom Reset"="@0";
"Original Size"="@0";
"Actual Size"="@0";
"Automatically Resize"="@9";
"Automatic Fit"="@9";
"Zoom to Fit"="@9";
"Enter Full Screen"="^@f";
"Exit Full Screen"="^@f";
"Enter Full Screen Mode"="^@f";
"Exit Full Screen Mode"="^@f";
"Toggle Full Screen"="^@f";
"Full Screen"="^@f";
"Fullscreen"="^@f";
"Normal Screen"="^@f";
"Remove Full Screen"="^@f";
"Select Previous Tab"="~@\UF702";
"Previous Tab"="~@\UF702";
"Show Previous Tab"="~@\UF702";
"Previous Workspace"="~@\UF702";
"Select Previous Tab View"="~@\UF702";
"Select Next Tab"="~@\UF703";
"Next Tab"="~@\UF703";
"Show Next Tab"="~@\UF703";
"Next Workspace"="~@\UF703";
"Select Next Tab View"="~@\UF703";
"Shift Left"="^\UF702";
"Decrease Indent Level"="^\UF702";
"Decrease Paragraph Indent"="^\UF702";
"Decrease Level"="^\UF702";
"Shift Right"="^\UF703";
"Increase Indent Level"="^\UF703";
"Increase Paragraph Indent"="^\UF703";
"Increase Level"="^\UF703";
"Shift Up"="^\UF700";
"Move Line Up"="^\UF700";
"Shift Down"="^\UF701";
"Move Line Down"="^\UF701";
"Minimize"="\U200B";
"Minimize All"="\U200B";
}'

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

defaults write -app iTerm NSUserKeyEquivalents '{
"Select Pane Above"="@\UF700";
"Select Pane Below"="@\UF701";
"Previous Pane"="@\UF702";
"Next Pane"="@\UF703";
"Open Autocomplete..."="@;";
}'

defaults write -app Safari NSUserKeyEquivalents '{
"Reopen Last Closed Window"="~@r";
"Reopen All Windows from Last Session"="~$@r";
"Mail Contents of This Page"="\U200B";
}'

defaults write -app Sequential NSUserKeyEquivalents '{
"Move to Trash"="\b";
}'

defaults write -app Skim NSUserKeyEquivalents '{
"Single Page Continuous"="$@0";
"Single Page"="$@1";
"Two Pages"="$@2";
"Crop"="@k";
}'

defaults write -app Transmit NSUserKeyEquivalents '{
"Show Invisible Files"="$@.";
"Hide Invisible Files"="$@.";
"Synchronize..."="$@y";
}'

defaults write -app WriteRoom NSUserKeyEquivalents '{
"Column 40"="$@1";
"Column 50"="$@2";
"Column 60"="$@3";
"Column 66"="$@4";
"Column 80"="$@5";
"Column 90"="$@6";
"Column 120"="$@7";
"Column 200"="$@8";
"Column Window Width"="$@0";
"Enter Full Screen Single"="^@f";
"Exit Full Screen Single"="^@f";
"Enter Full Screen"="$@f";
"Exit Full Screen"="$@f";
}'

The shortcut strings use the same format as in DefaultKeyBinding.dict, but delete is \U0008 (\b) and forward delete is \U007F.

You can disable a shortcut by assigning the menu item to something like \U200B (ZERO-WIDTH SPACE). nil would be triggered when you type n in some applications like Audacity. \0 would be triggered when you press any key in Safari in 10.9. \1 would be triggered when you press the home key.

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

defaults find NSUserKeyEquivalents shows current settings.

| improve this answer | |
  • I have a setup script with defaults write -g NSUserKeyEquivalents '{ "Zoom"="@$m";}' - What does the combination @$m do? Can you explain each of those, @, $, and m, and their usage? – Growler Dec 11 '16 at 21:01
  • @ for command, ~ for option, ^ for control, $ for shift – aafulei Jul 31 at 7:42
2

App shortcuts can be stored in two places:

  • The app-specific plist

    ~/Library/Preferences/com.apple.iTunes.plist
    
  • The Global Preferences plist

    ~/Library/Preferences/.GlobalPreferences.plist
    

Services shortcuts are stored in ~/Library/Preferences/pbs.plist.

| improve this answer | |
  • ~/Library/Preferences/pbs.plist doesn't seem to be the location on MacOS Sierra. Do you know where it is on Sierra? – Growler Dec 31 '16 at 1:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .