Is it possible to disable the command-tab application switcher in Mac OS X Lion?

11

5

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

Sean Mackesey

Posted 2012-07-25T03:01:42.497

Reputation: 405

possible duplicate. http://superuser.com/questions/548146/change-command-tab-to-option-tab-on-mac

– Daniel Dropik – 2015-06-22T16:42:47.767

Answers

6

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>

Lri

Posted 2012-07-25T03:01:42.497

Reputation: 34 501

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 – 2015-02-24T13:26:18.997

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 – 2012-07-27T04:04:06.777

1This 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 – 2013-11-08T05:44:41.963

1

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:

488D35691C2C008B3BBA01000000B901000000E85CD71B0085C0741A488B0DD5FC2400488B39488D355B341C0089C230C0E892C51B00488D0563192C008B38488D352A1C2C00BA02000000B901000000E81FD71B0085C0741A488B0D98FC2400488B39488D3541341C0089C230C0E855C51B00

with:

90909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090

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.

user2199684

Posted 2012-07-25T03:01:42.497

Reputation: 19

3This 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 – 2015-07-03T22:14:22.057

5can 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 – 2013-03-23T16:33:57.327

1Also add what the original code does, and the replacement (disassembly would be fine as far as I'm concerned) – vonbrand – 2013-03-23T17:05:33.007

0

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

Everett

Posted 2012-07-25T03:01:42.497

Reputation: 5 425

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 – 2012-07-25T03:20:12.690

3Agree 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 – 2012-07-25T04:31:57.220

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 – 2012-07-25T04:48:57.637

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 – 2012-07-25T05:31:07.403