153

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 menu item 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.

Ken
  • 1,573
  • 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 00: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
  • 1
    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. http://cl.ly/MDtE – bmike Jan 16 '13 at 20:00
  • bmike: I don't think so. I tried remapping Automator in the same way, and it shows command-option-Q in the menu but still quits when I press command-Q. I think it's OS X that's (half) ignoring the remapping. – Ken Jan 16 '13 at 20:04
  • You are right - this appears to be a Firefox bug and not an OS X issue. I've successfully remapped Command-Q on other apps, but firefox disregards these mappings (I used Q to map to About Firefox so it should open the about window in theory - but in practice, firefox still quits.) – bmike May 08 '13 at 15:40
  • My apologies for this promotion, but I have an open source app that will add a global delay to ⌘Q so that you can catch accidental ⌘Qs. https://github.com/dteoh/SlowQuitApps – dteoh Jun 27 '14 at 05:22
  • Related: http://apple.stackexchange.com/questions/45252/can-i-globally-change-the-cmd-q-shortcut-to-require-holding-for-two-seconds-lik – Stewart Apr 01 '16 at 12:08

16 Answers16

244

Go to System Preferences, then Keyboard. Select Shortcuts. On the left pane, find Accessibility. Now on the right pane enable Invert colors and then click on the shortcut box to reassign the shortcut to Cmd+Q.

That's it. Now when you press Cmd+Q the colors of the screen will be inverted. Press it again to go back to normal colors. No more accidentally quitting applications (like closing over two hundred tabs on Firefox when trying to use Cmd+a or three dozen pdfs on Preview when trying to use Cmd+tab; last two things I did, never again.)

P.S. Whoever thought it was a good idea to use Cmd+Q to quit applications should go back to usability school.


There's also a nice plugin that you can use called Always Ask, which forces a prompt dialog before leaving Firefox.

Daniel
  • 2,892
  • 28
    Just registered here to upvote this answer. Cmd+Q is the equivalent of making an @ symbol on a German PC-105 keyboard layout. Switching between PC and Mac is driving me crazy because I keep closing the browser when logging in somewhere. Thanks for the brilliant idea with inverting colors. – q9f Oct 14 '16 at 07:57
  • 9
    I assigned it to "Switch to desktop 1". Since I'm not using this feature anyway, it effectively does nothing. – tiktak Feb 11 '17 at 05:53
  • 8
    Bonus point for using Invert colors as a warning. Great UX feedback. – Jason May 23 '17 at 02:54
  • Is there a way to remap CMD+ESC to do the quitting system wide? – amar Oct 16 '17 at 04:26
  • 4
    I like your idea abou invert color , love it , it looks nerd – vanduc1102 Feb 09 '18 at 10:45
  • awesome. altho sometimes quit all is needed, like in case of stickies. so assigning it to different key combo is a good idea. – MartianMartian May 22 '18 at 04:04
  • This is the best idea I've seen in a while... – Darioush Aug 20 '18 at 23:29
  • 7
    You can also select Launchpad and Dock > Show Launchpad and set it to Cmd+Q. It's less annoying than your entire screen violently flashing when colors invert. – SiddharthaRT Aug 14 '19 at 19:35
  • @SiddharthaRT nice one – Jinhua Wang Sep 15 '19 at 16:03
  • 3
    One week of using a Mac and i've closed my IDE 15 times because i'm trying to pull up documentation of a function. Thank you! – cautionbug Dec 06 '19 at 17:08
  • 2
    Actually following this process I pressed command+Q accidentally again, which made me quit the system preference lol – Alan Jan 09 '20 at 06:54
  • 1
    I believe this stopped working on Catalina. Any way to disable Cmd+Q as easily as this on Catalina? – Shane Fontaine Jan 16 '20 at 17:00
  • 1
    @shane: I haven't tried it in Catalina. – Daniel Jan 17 '20 at 12:18
  • 2
    The number of times I have accidentally closed a program compared to the number of times in my life I've had to unnecessarily press a button on a dialog to confirm that, yes, I really want to do what I just said I want to do, yes, I know I'm closing it, yes, I know I didn't save, yes, please close the window, has got to be like 50 million to 1. Happens dozens of times per day. That's the real usability nightmare. – Wayne Mar 10 '20 at 19:36
  • 1
    I've closed System Preferences app with Cmd+Q when I was trying to assign this combination to another action :facepalm: – and1er Sep 06 '22 at 11:42
  • I made a script which rebinds Cmd+Q and Cmd+H for all installed applications: https://github.com/AnatolyRugalev/macos-unsuck – Anatoly Rugalev Feb 04 '23 at 17:12
21

I have found a way to do this without having to change your volume or stuff like that when you press command+Q.

go to system preferences -> keyboard -> mission control -> "do not disturb".

Then just click the box and change it to: command+Q.

dwightk
  • 7,619
  • 14
  • 47
  • 70
Helper
  • 211
  • 1
    Nice trick. Just want to add - if still want to keep the ability to quit your app using shortcut, but there's no such preferences, then you can do so going to Settings -> Keyboard -> tab Shortcuts -> from left items list select App Shortcuts -> press + button, add your app -> Important! type exactly Quit and assign your shortcut. Enjoy! https://i.ibb.co/PzHvfRh/Screen-Shot-2019-09-04-at-10-38-12-AM.png – Stanislau Baranouski Sep 04 '19 at 03:42
  • 1
    Works for me. This is better than the invert colors trick marked as the answer. – Thomas Eding Nov 18 '19 at 04:21
12

Sorry for digging up such old post but this idea may be useful.

In System Preferences - Keyboard create a new shortcut for the application you want to prevent quit. Search for the title of the quit command in the application's menu and enter the same exact as a Menu Title for the shortcut, then give a different shortcut.

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

totymedli
  • 545
user67010
  • 121
  • 1
  • 2
  • 1
    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. – grg Jan 10 '14 at 15:27
  • 2
    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 '14 at 12:43
  • I followed this link that describes the same solution and that worked perfectly for me. – totymedli Jan 12 '15 at 00:57
  • I just added an "Option Q" shortcut for "Quit Firefox" as an Application specific (Firefox) shortcut for Firefox. In Firefox, my "Quit Firefox" menu item now shows opt Q, and cmd Q no longer quits the App, but opt Q does. You have to get the text of the menu item exactly right. Oh, I see, we're a couple years into the future here; with OS X 10.12.3. and Firefox 51.0. – Wayfaring Stranger Feb 08 '17 at 21:03
  • 1
    Good fit for Safari (Safari respects the shortcut), and a sanity-saver for those of us who often hit CMD+Q instead of CMD+W. – AncientToaster Jul 18 '17 at 05:21
  • I found this to be the optimal solution for games. – Alex P Mar 22 '20 at 23:49
  • If after update the shortcut doesn't work anymore, try to delete it and create it again – ganqqwerty May 15 '20 at 16:32
8

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>
Lri
  • 105,117
  • 2
    On Karabiner Elements (the successor to KeyRemap4MacBook), there's a "complex modification" that can be downloaded online that achieve the same job: https://pqrs.org/osx/karabiner/complex_modifications/#command_q Changing the Safari option to Firefox or some other browser is just a matter of changing the app bundle regex inside the config JSON (which should be located at ~/.config/karabiner/assets/complex_modifications). – Gustavo Bezerra Dec 02 '17 at 08:19
  • @GustavoBezerra can I please talk to you about doing this in Karabiner elements? Would you mind to join a chat room with me about it? – Arlen Jun 10 '22 at 08:04
6

You can disable Cmd + Q by using BetterTouchTool (a wonderful app) for Mac OS:

Go to Keyboard -> Add new shortcut or key sequence -> map Cmd+Q to "No Action"

enter image description here

Dio Phung
  • 201
  • 3
    You don't really modify the command, you just tell the system to prioritise another action. I find this incredibly hacky, as you can't re-use the command for anything else this way. – BlkPengu Feb 14 '21 at 21:11
  • @BlkPengu Apple is known for providing a consistent user experience. – Evan Carroll Apr 24 '23 at 04:41
  • @BlkPengu : the question is how to disable Cmd + Q, so I'm suggesting a solution. Meanwhile, you can still map Cmd + Q to something else if it's supported by BetterTouchTool – Dio Phung Apr 24 '23 at 22:33
  • @DioPhung I'm not saying your solution is invalid, just that I find it isn't elegant or pretty. – BlkPengu May 03 '23 at 20:21
5

QBlocker

QBlocker is a free and open source app by to solve this issue by requiring a user to hold down CMD+Q to quit all apps or just certain ones.

Steve Moser
  • 8,734
  • 1
    this is a good option but someone says that it is stealing chrome cookies. please can you look at this: https://github.com/steve228uk/QBlocker/issues/34 – kodmanyagha Feb 14 '21 at 10:21
4

Now there is an item in the Chrome application menu "Warn Before Quitting" which does the trick for me.

Source: http://lifehacker.com/5784153/how-to-bring-back-the-hold-q-to-quit-prompt-in-google-chrome

freemanoid
  • 191
  • 1
  • 6
4

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.

grok
  • 41
  • 1
    Now called Karabiner: https://pqrs.org/osx/karabiner/ Does not work under 10.12, will handle earlier OS's. There's a pre-written shortcut for globally changing cmd Q to something else here: https://pqrs.org/osx/karabiner/list.html.en under Custom Shortcuts – Wayfaring Stranger Feb 08 '17 at 16:12
3

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.

Hank
  • 491
  • 10
    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
2

Go to System Preferences>Keyboard>Shortcuts then the application button on the left bar. Press the + button then Choose your application. Write "Quit (Application Name)" in the Menu Title Slot. Add your command to replace cmd-q and that's it.

Macpro
  • 31
2

The best way I found is next.

When I click Cmd + Q it locks my screen.

To achieve this:

  • Run System Settings
  • Select Keyboard in sidebar
  • Press Keyboard Shortcuts button
  • Select App Shortcuts in sidebar
  • Press on Plus (+) button
  • Write Lock Screen and assign it to Cmd + Q combination
  • Press Done button

Add Cmd+Q for Lock Screen Add a new item Lock Screen for All Applications You will see a new shortcut in the Apple logo menu

0

Simply I have replaced the existing command with new one,

Ex. I replaced Quit command for Sublime Text for MAC,

I used to Add new shortcut and added new command alt+command+c

0

There is on solution not posted here that I thought should merit consideration. If you don't mind removing the command+q entirely from your computer you can effectively remap in Ukulele so that Command+Q execute another keyboard shortcut.

You could make it execute command+space or command+1 just assign it to something else.

There are positives and negatives to this approach but it should work.

William
  • 1,658
0

Go to settings → Keyboard → shortcuts → App-keyboardshortcuts(on my mac: 'App-Tastenkurzbefehle') Press '+' Then add shortcut for the programm you wish to deactivate Command+Q. Afterwards type exectly the name of the menu point! Because my mac is geraman there is written 'Safari beenden'.

I prefer this solution because I still can close safari with a short cut but I am not doing it by accident. enter image description here

lars
  • 1
0

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.

Insomniac Software
  • 1,893
  • 11
  • 14
-1

use Switcher can prevent you to press cmd + q by mistake

qqabb
  • 1