This shortcut drives me crazy. I would like to remap command-tab for snippet insertion while coding, but the switcher gets in the way...


You can map command-tab to another key combination with KeyRemap4MacBook:

<autogen>__KeyToKey__ KeyCode::TAB, VK_COMMAND | ModifierFlag::NONE, KeyCode::F19</autogen>

This would disable command-tab and shift-command-tab:

<autogen>__KeyToKey__ KeyCode::TAB, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
<autogen>__KeyToKey__ KeyCode::TAB, VK_COMMAND | VK_SHIFT | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
  • Thanks, this is a good lead. It's also good to know that remapping via DefaultKeyBinding.dict is a dead end. I'll try out KeyRemap4MacBook – Sean Mackesey Jul 27 '12 at 4:04
  • 1
    This worked great, thanks. In case it isn't clear to others, you need to add these definitions to private.xml in it's own <item> tag under <root>. Then, reload private.xml and toggle the new option. – jrhorn424 Nov 8 '13 at 5:44
  • Make sure to add a name and an identifier to the <item> entry <name>Disable Command Tab</name> <identifier>private.disable_command_tab</identifier> – Willem D'Haeseleer Feb 24 '15 at 13:26

You can do it as the assembly level. For ML 10.8.3, this Cmd+Tab registration happens in subroutine at address 0x10000b258. In pseudo-code, it looks like:

rax = CPSRegisterForKeyOnConnection(*(int32_t *)rbx, 0x1002cd078, 0x1, 0x1);
if (rax != 0x0) {
    fprintf(**__stderrp, "Error registering cmd-tab key, %d\\n");
rax = CPSRegisterForKeyOnConnection(*(int32_t *)0x1002ccda8, 0x1002cd078, 0x2, 0x1);
if (rax != 0x0) {
    fprintf(**__stderrp, "Error registering cmd-shift-tab key, %d\\n");

So if you replace the following byte codes:




And resign your Dock.app, it will work. You also have to unprotect the Dock binary before you do this as the Dock binary is encrypted.

  • 5
    can you please backup your answer with some kind of source please? all that code can be confusing and object of mistrust by future readers. hope you understand. – Lorenzo Von Matterhorn Mar 23 '13 at 16:33
  • 1
    Also add what the original code does, and the replacement (disassembly would be fine as far as I'm concerned) – vonbrand Mar 23 '13 at 17:05
  • 3
    This is a pretty cool answer. While the concern in the other two comments is probably valid, its a bid sad that all the comments are questioning it, but no one points out that this is pretty cool. How do you know which subroutine address, and what is the 090909 ? (no-op ?) – Gal Jul 3 '15 at 22:14

Would an acceptable answer include remaping it?

Mac OS X Lion (10.7) has difficulty detecting the keyboard layout when I first plugged it in. But after following the instructions (i.e. press the key to the right of Left Shift, etc.) it correctly identifies the layout.

In System Preferences, Lion has a wonderful keyboard panel:

Screen shot of Lion's keyboard panel

Next, go to Modifier Keys…

enter image description here

Bingo, now CapsLock behaves as Control.

Or, you could try and effect the key bindings:

Edit the default keybindings file, ~/Library/KeyBindings/DefaultKeyBinding.dict. Create the directory and/or the file if they’re not already there, and make it look like this:

  /* Remap Home / End to be correct */
  "\UF729" = "moveToBeginningOfLine:"; /* Home */
  "\UF72B" = "moveToEndOfLine:"; /* End */
  "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
  "$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */

If there are already entries in DefaultKeyBinding.dict, just add the 4 new mappings above to the main section of your file. A reboot may be needed to get it to take effect.

You will need to adjust the code above for what you are trying to do

  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Canadian Luke Jul 25 '12 at 3:20
  • 3
    Agree with the above commenter-- this answer is far too roundabout. I appreciate your attempted answer, but please try to be more direct. I feel like this entry is just likely to confuse others who find this question in the future. Also, remapping the entire command key to something else is not an acceptable solution for me, as I use the command key for many other things. I can't tell if the code you show in the second part of your solution would allow me to selectively disable CMD+TAB, but if it can please explain how explicitly. – Sean Mackesey Jul 25 '12 at 4:31
  • Remapping the command key to Caps Lock is probably the best idea I could offer. You still get the command key, and I'd be stunned to hear you are actually using caps lock for something. The second option was to demonstrate the amount of work you were going to have to do if you have a reason why the easy way won't work. Outside of these two I have nothing else for you. I provided the essential parts as Luke recommended. – Everett Jul 25 '12 at 4:48
  • I actually have CapsLock remapped to Escape already (essential if you use Vim!). Thanks for your effort, again I'm going to recommend you edit your post though. Please just link to something about remapping modifier keys, so that future browsers won't have to wade through the whole explanation when they know that that solution won't work for them. – Sean Mackesey Jul 25 '12 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.