14

I am trying to create a few system level key bindings. I know about ~/Library/KeyBindings/DefaultKeyBinding.dict but I am not sure what to put in there/or how to go about finding the commands and codes.

I would like keybindings to

  • Opt <- //Move cursor back a word
  • Opt -> //Move cursor forward a word
  • Opt Cmd <- //Home
  • Opt Cmd -> //End
  • (the same commands, but adding Shift to select instead of just move

Is there a good resource to help me figure this out?

5 Answers 5

17

There is a wonderful resource on DefaultKeyBinding.dict including an example file as well as all the shortcut strings and methods you need, available at:

There are also numerous other resources listed at the bottom of the page, including the official Apple Developer documentation:

2
6

The accepted answer still provides good sources for key codes, however a full list of commands is now available from Apple here:

https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding

1

2020 answer:

I'm using Karabiner

It used to be called KeyBindingsEdit which the other answer links to

It comes with a UI, you can import rules that other people have uploaded, and you can make your own through JSON format file

Here are my configs for moving cursor forward/backwards a word:

(I didn't check if the parenthesis are matching properly, confirm that the format is correct on your file)

{
  "title": "personal rules",
  "rules": [
      {
      "description": "cmd + arrow to ctrl + arrow",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "right_arrow",
            "modifiers": {
              "mandatory": [ "command" ],
              "optional": [ "any" ]
            }
          },
          "to": [
            {
              "key_code": "right_arrow",
              "modifiers": [ "control" ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "left_arrow",
            "modifiers": {
              "mandatory": [ "command" ],
              "optional": [ "any" ]
            }
          },
          "to": [
            {
              "key_code": "left_arrow",
              "modifiers": [ "control" ]
            }
          ]
        }
      ]
    }

]
}

You would add it to ~/.config/karabiner/assets/complex_modifications/<customname>.json

2
  • It looks cool, but I tried installing Karabiner and it immediately messed up all my existing shortcuts/hot keys
    – Aximili
    Commented Mar 29, 2022 at 2:01
  • @Aximili that's a shame! I like it because if I move to a different computer I can easily carry all my shortcuts by copy/pasting the configuration file, worth the trouble
    – Jose V
    Commented Mar 31, 2022 at 21:06
1

I found an application (KeyBindingsEdit) that is a nice UI for building it. If you are just looking for a good way to edit it, it could be helpful

1
  • Sadly, this no longer works with on Mac OS Ventura. Commented Oct 31, 2022 at 0:47
1

2024 update:

Many resources you find on the internet just tell you their setup, but does not tell you how they discovered them(which I hate). They surely don't contain all the bindable methods supplied by AppKit you may find helpful, like "convertToTraditionalChinese:". Or tell you that shift+tab is represented as 0x19 in StandardKeyBinding.dict.

So I found a way to extract bindable commands right from AppKit, using symbols /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit | grep KeyBindingCommands. Unfortunately I haven't found the way to do this on Ventura, so i only got a dump from Catalina here https://gist.github.com/hym3242/4ade5dbcabbe547f3d78687897b8ddfe.

also see https://gist.github.com/hym3242/8e8bc10a2fed8e55973c500f1798c234

Regarding the defaults write -g NSRepeatCountBinding -string "~r" trick, you can find NSRepeatCountBinding string in AppKit exe, so it would obviously require some reverse engineering to find that!

You must log in to answer this question.