Remap Keys via Command Line in Mac OS X

Solution 1:

Application-specific keyboard shortcuts like those from System Preferences are stored in the preference files of the corresponding application in /Users/username/Library/Preferences/, in the top-level NSUserKeyEquivalents key.

Those files can be read and written using the /usr/libexec/PlistBuddy and defaults programs on the command line.

$ defaults read com.apple.Automator NSUserKeyEquivalents
{
    "Hide Library" = "@$l";
    "Show Library" = "@$l";
}
$ defaults write com.apple.Terminal NSUserKeyEquivalents -dict-add "About Terminal" '^@$a'

Symbols and their meanings:

  • @ is Command
  • $ is Shift
  • ^ is Control
  • ~ is Option

Additionally, you can simply copy these files to other machines to take your user preferences with you.