Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Command-Q is the worst keyboard shortcut ever: processes are started/stopped automatically these days, so "Quit" in many cases just means "destroy my current work session". With my keyboard layout, it's even worse, since "command" and "Q" are adjacent, so it's way too easy to do this accidentally.

I just lost a whole bunch of Firefox windows because of this.

Is there any way to disable command-Q for quitting apps?

I tried adding this menuitem to the "Keyboard Shortcuts" preference pane (as suggested here), and remapping it to command-option-Q (slightly harder to hit), and the menuitem changed to show this, but command-Q still causes the app to quit.

I'm using OS X 10.7, but I'd happily upgrade to 10.8 if it fixed this.

The app I really want this for is Firefox, but if there was a solution that disabled command-Q for every app, that would be fine, too.

share|improve this question
1  
Are you looking for a global hack or would you be able to just remap the applications you want to override? The latter is quite easy using the normal keyboard preference pane and making another shortcut (like command - shift - control - option - Q) that won't get pressed on a whim. –  bmike Jan 15 '13 at 21:02
    
bmike: I'd take either, but as I said, I tried making it command-option-Q and it doesn't work. If I try entering command-option-shift-Q, it beeps and says the app System Prefs has cancelled logout. –  Ken Jan 15 '13 at 23:45
    
The problem is you need to over ride quit on a per application basis and include the app name so that the full menu name is entered in the app-specific shortcut. –  bmike Jan 16 '13 at 0:02
    
bmike: I was specifying the override for Firefox only, and including the app name in the menuitem override. –  Ken Jan 16 '13 at 19:58
    
Hmm - I didn't read the question to mean that Firefox intentionally disregards keyboard shortcut defined by OS X - but perhaps that's what you are seeing based on the comments? I wonder if perhaps they implemented a shortcut remapping function? It's been a while since I've had the fox running. Choosing a command like ⌃⇧⌘Z works to make Command-Q insensitive for Mail and Safari - see this picture for how I set the shortcuts up. cl.ly/MDtE –  bmike Jan 16 '13 at 20:00
show 2 more comments

5 Answers

Use a keyboard remapper. There's a great GPL one for OSX (I use Keyremap4MacBook) Just map the command Q key combo to something that does nothing.

share|improve this answer
add comment

Not a direct answer to your question, but you can tell Firefox to automatically open your old windows when you launch it using the When Firefox starts option under the General preferences pane.

If you don't want to change your start screen just for the occasional accidental quit, there is also a command to do it: History menu -> Restore Previous Session.

share|improve this answer
    
Yes, but if there are many windows/tabs open, that can take quite a while, and some won't be able to recover their session/state completely. It also annoyingly restores all windows onto the current space, rather than the space they were on previously. –  Ken Jan 16 '13 at 20:01
add comment

Using KeyRemap4MacBook, you could add this to private.xml:

<item>
  <name>disable_command_q</name>
  <identifier>disable_command_q</identifier>
  <autogen>__KeyToKey__ KeyCode::Q, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_NONE</autogen>
  <autogen>__KeyToKey__ KeyCode::Q, VK_COMMAND | VK_SHIFT | ModifierFlag::NONE, KeyCode::Q, ModifierFlag::COMMAND_L</autogen>
</item>

Without | ModifierFlag::NONE the first autogen element would also disable for example ⌥⌘Q. The second autogen element changes ⇧⌘Q to ⌘Q.

There are also predefined settings that make sending ⌘Q require holding ⌘Q or pressing ⌘Q twice:

They are defined in custom_shortcuts.xml:

<item>
  <name>Hold Command+Q to Quit Application</name>
  <appendix>(You can adjust the threshold time of holding by</appendix>
  <appendix>"[Holding Key to Key] Holding Threshold" in Key Repeat tab.)</appendix>
  <identifier>remap.holdcommandQ</identifier>
  <autogen>__HoldingKeyToKey__ KeyCode::Q, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_NONE, KeyCode::Q, VK_COMMAND, Option::NOREPEAT</autogen>
</item>
<item>
  <name>Press Command+Q twice to Quit Application</name>
  <identifier>remap.doublepresscommandQ</identifier>
  <autogen>__DoublePressModifier__ KeyCode::Q, VK_COMMAND | ModifierFlag::NONE,
    KeyCode::VK_NONE,
    KeyCode::Q, VK_COMMAND
  </autogen>
</item>
share|improve this answer
add comment

As you have seen, just setting a new keyboard shortcut in the System Prefs doesn't always work. It will change the shortcut shown in the menu but the application could still be listening for the Commmand+Q keypress. I've seen a few apps that do this. Even some will listen to keypresses that are not listed as shortcuts in the menu (Photoshop for example).

A 3rd party option is to use something like ControllerMate. It has the ability to remap any controller input (keyboard, mouse, trackpad, joystick, etc) and change what it does. I use it to do many remaps and run macro scripts. They can be set on a per-application basis or a global system-wide state.

Using ControllerMate, you could map Command+Q to do nothing then have Command+Option+Q call the Quit menu entry. Or you could get fancy and have Command+Q do nothing except if you press Command+Q again within 1/2 of a second then it would call the Quit menu.

ControllerMate is an amazing app. I've done many customizations like a "Boss/Spouse Mode" which is a single keypress that does the following

  • mutes the computer audio
  • pauses iTunes if it is playing
  • quits QuickTime and/or VLC if it is running
  • minimizes current Firefox windows and opens a new window to Google.com

Another suggestion (along with Henry's suggestion) is to use a session manager so if Firefox is quit by accident, you can restore easily. The built-in session manager is OK but you should also look at Tab Mix Plus. Not only does it give you amazing options for managing your tabs but its session manager is also great. I have many sessions saved and can pull them up quickly anytime in new windows.

share|improve this answer
add comment

Sorry for digging up such old post but this idea may be useful. http://www.howtogeek.com/howto/39520/how-to-change-the-cmdq-shortcut-key-in-os-x-to-stop-accidentally-closing-apps/

Indeed, you don't have this issue with all applications but only browser and maybe one or two other apps.

share|improve this answer
    
Welcome to Ask Different! While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  grgarside Jan 10 at 15:27
    
This solution doesn't apply to firefox. Firefox shows the new shortcut in its menu. But it doesn't work. cmd-q still closes the browser... –  JerryWho Jan 28 at 12:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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