Modifying Mac Hotkeys

posted April 29, 2009 by daniel

There's a variety of ways to change hotkeys in OS X 10.5 Leopard.

System Hotkeys

System Hotkeys To change system hotkeys, such as command-shift-3 to save a screenshot, open System Preferences, then open the Keyboard & Mouse preference panel and change the hotkeys on the Keyboard Shortcuts tab. I've disabled the Front Row hotkey because I press it by accident fairly often.

 

Application Hotkeys

Application Hotkeys You can change hotkeys defined in application menus and even add hotkeys to menu items that don't have hotkeys. This is similar to changing system hotkeys. Open System Preferences, then open the Keyboard & Mouse preference panel, switch to the Keyboard Shortcuts tab and scroll all the way to the bottom where Application Keyboard Shortcuts is listed. Press the plus [+] button under the list, choose an application from the list. Now the tricky part is that you have to type the name of the menu item exactly as it appears in the menu in the box labelled Menu Title. Then enter a hotkey in the box below. You may need to quit the application for the changes to take effect. For example, I like to open bundles with a hotkey rather than using the context menu. (This works for context menus, not just the main menu.) I choose Finder in the application list, then enter Show Package Contents in the Menu Title box and then put option-command-s in the hotkey box. Now, when I select a bundle in Finder and press option-command-s, a new window showing the bundle's contents appears. Another example is choosing All Applications in the drop-down list, entering Zoom for the Menu Title and option-command-M in the hotkey box. That will allow you to maximize windows in any application with a hotkey.

Text-editing Hotkeys

Keys and hotkeys on OSX are very flexible if you're willing to read some documentation and edit a text file to change your settings. You may need to restart an application for the changes to take effect and it only works in Cocoa apps, not Carbon. Windows users will appreciate this because they can change their Home and End keys to work like they do in Windows. I've reproduced my DefaultKeyBinding file below as a starting point, and there's an exhaustive list of the ways you can customize Mac keys if you feel like doing your own thing. There's even a GUI keybinding editor if you don't like editing a text file.


/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
    "@~^z"        = "revertDocumentToSaved:";
    "\UF729"      = "moveToBeginningOfLine:";      /* home */
    "$\UF729"     = "moveToBeginningOfLineAndModifySelection:";
    "\UF72B"      = "moveToEndOfLine:";            /* end */
    "$\UF72B"     = "moveToEndOfLineAndModifySelection:";
    "^\UF729"     = "moveToBeginningOfDocument:";  /* control + home */
    "^\UF72B"     = "moveToEndOfDocument:";        /* control + end */
    "\UF72C"      = "pageUp:";                     /* page up/down */
    "\UF72D"      = "pageDown:";
    "$\UF72C"     = "pageUpAndModifySelection:";   /* shift + pgup */
    "$\UF72D"     = "pageDownAndModifySelection:"; /* shift + pgdn */
    "@~^v"        = "pasteAsPlainText:";
    "^w"          = "deleteWordBackward:";         /* M-C-h */
    "~^f"         = "moveWordForward:";            /* M-f */
    "~^b"         = "moveWordBackward:";           /* M-b */
    //  "~<"      = "moveToBeginningOfDocument:";  /* M-< */
    //  "~>"      = "moveToEndOfDocument:";        /* M-> */
    //  "~v"      = "pageUp:";                     /* M-v */
    //  "^v"      = "pageDown:";                   /* C-v */
    //  "~d"      = "deleteWordForward:";          /* M-d */
    //  "~^h"     = "deleteWordBackward:";         /* M-C-h */
    //  "~\010"   = "deleteWordBackward:";         /* M-backspace */
    //  "~\177"   = "deleteWordBackward:";         /* M-delete */
    //  "~\UF728" = "deleteWordForward:";          /* delete */
    //  "@\UF729" = "moveToBeginningOfParagraph:"; /* A-home */
    //  "@\UF72B" = "moveToEndOfParagraph:";       /* A-end */
    //  "@\UF700" = "moveToBeginningOfDocument:";  /* A-up */
    //  "@\UF701" = "moveToEndOfDocument:";        /* A-down */
    //  "^\UF700" = "pageUp:";                     /* C-up */
    //  "^\UF701" = "pageDown:";                   /* C-down */
    //  "^/"      = "undo:";                       /* C-/ */
    //  "~c"      = "capitalizeWord:";             /* M-c */
    //  "~u"      = "uppercaseWord:";              /* M-u */
    //  "~l"      = "lowercaseWord:";              /* M-l */
    //  "^t"      = "transpose:";                  /* C-t */
    //  "~t"      = "transposeWords:";             /* M-t */
    //  "~/"      = "complete:";                   /* M-/ */
    //  "^g"      = "_cancelKey:";                 /* F5 */
    "^a"          = "moveToBeginningOfLine:";      /* C-a */
    "^e"          = "moveToEndOfLine:";            /* C-e */

/* complex hotkeys (like TextMate) */
"^$K"         = ("moveToBeginningOfLine:", "deleteToEndOfLine:", "deleteForward:"); /* delete current line */
"^$J"         = ("moveToEndOfLine:", "deleteForward:"); /* join next line to current line */

/* Modifier keys: start with C-m */
"^m" =
{
    "a"     = ("insertText:", "\U2318");  /* a       command (apple)    &#8984; */
    "o"     = ("insertText:", "\U2325");  /* o       option             &#8997; */
    "c"     = ("insertText:", "\U2303");  /* c       control            &#8963; */
    "s"     = ("insertText:", "\U21E7");  /* s       shift              &#8679; */
    "l"     = ("insertText:", "\U21EA");  /* l       caps lock          &#8682; */
    " "     = ("insertText:", "\U2423");  /* space   space              &#9251; */
    "r"     = ("insertText:", "\U21A9");  /* r       return             &#8617; */
    "e"     = ("insertText:", "\U2305");  /* e       enter              &#8965; */
    "t"     = ("insertText:", "\U21E5");  /* t       tab                &#8677; */
    "^t"    = ("insertText:", "\U21E4");  /* C-t     backtab              */
    "d"     = ("insertText:", "\U232B");  /* d       delete             &#9003; */
    "^d"    = ("insertText:", "\U2326");  /* C-d     forward delete     &#8998; */
    "b"     = ("insertText:", "\U2190");  /* b       solid left         &#8592; */
    "f"     = ("insertText:", "\U2192");  /* f       solid right        &#8594; */
    "p"     = ("insertText:", "\U2191");  /* p       solid up           &#8593; */
    "v"     = ("insertText:", "\U2193");  /* v       solid down         &#8595; */
    "^b"    = ("insertText:", "\U21E0");  /* C-b     dotted left        &#8672; */
    "^f"    = ("insertText:", "\U21E2");  /* C-f     dotted right       &#8674; */
    "^p"    = ("insertText:", "\U21E1");  /* C-p     dotted up          &#8673; */
    "^v"    = ("insertText:", "\U21E3");  /* C-v     dotted down        &#8675; */
    "h"     = ("insertText:", "\U2196");  /* h       home               &#8598; */
    "^h"    = ("insertText:", "\U2198");  /* C-h     end                &#8600; */
    "u"     = ("insertText:", "\U21DE");  /* u       page up            &#8670; */
    "^u"    = ("insertText:", "\U21DF");  /* C-u     page down          &#8671; */
    "x"     = ("insertText:", "\U238B");  /* x       escape             &#9099; */
    "j"     = ("insertText:", "\U23CF");  /* j       eject              &#9167; */
};

}