Anyone knows of a way to cancel "Cmd Q" on a Mac?

I am looking for a way to cancel the Cmd Q shortcut and replace it with with "Cmd ".
Anyone knows of a script/terminal command/any other way that will do that? (Of course I can create a KM shortcut for the Cmd \ to invoke the Cmd Q and quit a program, but then I have 2 shortcuts to quit programs instead of 1).

Hey Saul,

You can probably do that in the System Keyboard Prefs, but you’d have to do it for every app.

-Chris

Hi Chris.
Thanks for your response.
Sorry, didn’t mention it but tried that before posting the question. Didn’t find any way in the preferences (will be happy to hear though).

Thanks
Saul

Hey Saul,

Google:

os x change application keyboard shortcuts

-Chris

Hey Chris.
How come I din’t think about googling?! (Usually I do…) :smile:

Thanks! I found this link for Yesemite and am gonna try:

https://support.apple.com/kb/PH18418?locale=en_US

Will post here if it worked.

No-one has said this, so…

Saul, this seems like a really bad idea. What’s the reason?

Chris, started trying. Not sure yet but I think what you pointed me to is going to add a shortcut to the existing one (meaning the Cmd \ will quit a program, but so will the Cmd Q and I am looking to replace it.

CareyB, if you could tell me why is that a bad idea it will be great. The reason I wanted to eliminate/replace Cmd Q is that I hit it sometimes instead of Cmd W (quit current page/tab) (then, instead of quitting one tab in the browser I quit the whole app) (I could “train myself” to better/more accurately hit the keys but… :slight_smile:

Apologize in advance if it takes me a while to get back, it’s just that another granddaughter is being born…:slight_smile:
Thanks to both of you!

Well, if that is the reason, someone posted a better way here - put a KBM macro in your Safari-only group that brings up a warning box when you hit Cmd-Q (quitting Safari from the menu will work as always). With the following script, simply ExecuteAppleScript with Cmd-Q as the trigger and the following script as the text script:

tell application "System Events"
	set theName to name of the first process whose frontmost is true
end tell
tell application theName
	display dialog "Are you sure you want to quit?"
	quit
end tell
1 Like

Hey Saul,

The screenshots I posted plainly demonstrate that Q is REPLACED by \ in TextEdit.

That's how the System's Keyboard App Shortcuts work.

If you have found an instance where this is NOT true then please disclose the relevant application.

-Chris

I am sorry. I see that I didn't explain myself as I should and was misunderstood.
I am looking for a System-wide replacement.
As far as I understood the solution with the System preferences>Keyboard>Shortcuts>Applications>"+" works with all applications whenever the command is the same (E.G if I assign, let's say Cmd / for closing a window, it will replace the default shortcut (Cmd W) with the Cmd / in all applications that use this shortcut with that name ("Close") which will be, let's say, Word, Excel, Text Edit and so, but it won't replace it in Chrome because the Cmd W shortcut is for (as it is defined in the File submenu) "Close Tab" and not just "Close".
So, the Cmd Q is not going to be replaced System wide because in every application Cmd Q is defined not just as "Quit", but "Quit application name (Quit Google Chrome, Quit Word and so on).

I found a work around (I am looking for more like a "KM based shortcut", avoiding using scripts or so, because I am not big in scripts) (I'm not big in KM either, but I'm learning) :slight_smile:
First I created a simple macro ("Replace Cmd Q with Cmd ")

But that just creates an additional shortcut. Now every application will quit with either "Cmd Q" or "Cmd "

Then I added a 2nd macro ("Activate/deactivate Cmd Q")

Whenever the 2nd shortcut is active, Cmd Q is deactivated System wide and replaced by Cmd .

I have no idea if I am doing something "that shouldn't be done". :slight_smile: So far it works for me.

Please let me know what you think.

P.S. I see that my screen shots turned out huge, I am sorry, have no idea how to "shrink" it... (would be happy to hear how to "control" it next time) :slight_smile:

Hey Saul,

I did mention in my first post that you'd have to set a keyboard shortcut on a per application basis to use the System Prefs to do this.

So. It's easy enough to intercept Q in any application by using a global macro.

Quit → Intercept ⌘-Q.kmmacros (1.5 KB)

It's a little trickier to let \ manage quitting any given application, but once you know the secret it's not so difficult.

You have to know that the Select or Show a Menu Item action will accept 'APPLICATION' as a token for the front application, and you also have to know that it can use a regular expression by prefixing the text with a Caret "^" character.

https://wiki.keyboardmaestro.com/action/Select_or_Show_a_Menu_Item

Quit → Quit the Front Application.kmmacros (1.6 KB)

I fixed them. Do you have a Retina Mac? If that's the issue you can just divide the height and width in the link in the editor by 2.

-Chris

1 Like

Saul,

My experience is that overriding system level defaults never works well. There may be something that depends on it we don’t know. You may interfere with some update, or reboot, or something else. I don’t know for sure, but I’ve had it happen to me before.

I like rollan’s solution, or, to make the whole thing less drastic, override the CMD+W.

I think the key proximity is probably something we’ve all run into. I’ve certainly quit a program when I only wanted to close a window. And don’t get me started on going back and forth from Windows to OS X to Linux and back.

Hi Chris, rolian and CareyB.
Chris, I am currently checking your reply. Something is not working for me and I’m trying to pinpoint why/what. I’ll get back as soon as I find (or don’t find) the problem.

rolian, your suggestion looks easy. Thanks for it, but I’m trying to “stay” within KM. I started learning applescript but didn’t get too far yet and I’m trying to use whatever I understand better. (It will be easier for me, if something is not working, to find the answer/solution in KM than in AS, even if it may not be as “elegant”).

CareyB,

[quote=“CareyB, post:12, topic:2630”]
My experience is that overriding system level defaults never works well
[/quote]What your saying makes sense so I’ll end up intercepting Cmd W instead of Cmd Q, thanks for your help.

OK, I think eventually we got what I wanted. (Thanks to all of you who helped me)!
:+1: :+1: :+1:

I followed CareyB's advice and replaced the Cmd W (close window) shortcut.

The intercepting macro was simple and easy. The action I chose was one that has "no results" and can be replaced with many others. (I didn't want any pop ups/sounds or so).

Intercept Cmd W.kmmacros (2.2 KB)

(The image should look fine this time- ***thank you ccstone!!!***)

Then I did a 2nd macro to close the window with Cmd \ (also fairly simple, since the Cmd W shortcut was not replaced, only intercepted).

BTW, the combination of both shortcuts worked fine with "replacing" Cmd Q system-wide.

Close a window with Cmd - instead of Cmd W.kmmacros (1.6 KB)

Chris, I don't know why but when I tried your macro it work partially, (the "intercepting one" worked perfectly and the sound was "loud and clear) :smile:

When I hit the Cmd \ shortcut it quit all the applications I tried except the Office ones (Word and Excel).
Instead I got the following error message:

BTW, the macros I did previously (basically the same ones as those above, just instead of replacing Cmd W they replaced Cmd Q) worked fine with Office too.

But... from the other hand... I'm used to have problems with the MS Office... :slight_smile:

Thanks for all your help!

Well, Q is an application-level keyboard shortcut and not a system-level one.

Tinkering with the system without knowing what you're doing WILL come back and bite you at some point though. Even those who are well-versed in such things get nipped now and then.

All that said I wouldn't have any problem overriding Q. There are plenty of alternatives, and you can always quit the Keyboard Maestro Engine to disable all macros if need be.

-Chris

Hey Saul,

This is because Microsoft apps all have “Microsoft <app-name>” as the application name but only show Word/Excel/PowerPoint in the application menu.

Keyboard Maestro is getting the full app-name when replacing the token APPLICATION, so of course there's a failure.

I rate this as a bug caused by Microsoft apps non-standard behavior.

Peter can work around it if he wants to (I'll report it), but the user can work around this as well.

I'll post a fix here in a bit.

-Chris

Hey Saul,

Okay, here's the fix. It's working on my system with Word, Excel, and PowerPoint.

matches in context means matches a regular expression.

So I'm special-casing Microsoft apps and using the APPLICATION token for everything else.

-Chris


Quit → Quit the Front Application.kmmacros (4.2 KB)

Well, perhaps it is an application-level shortcut, but it is a long-standing Mac shortcut that works with every Mac app I've ever used.

Frankly, IMO, this is a use case few users would ever be interested in. Long, long, ago, I developed muscle memory for typing ⌘Q, but then I've been a touch typist since high school. I'm with @CareyB on this, I wouldn't mess with it.

Just my opinion. That's the great thing about KM -- it lets each of us customize our environment to our liking.

KM is now my favorite app by a long shot. :+1:

Saul – this is confusing, since your altered actions as shown deal with W and NOT Q.

Saul specifically requested the Q intercept, and Keyboard Maestro allows users with edge-case needs to fulfill them (much of the time).

W is much more frequently used than Q, but you're not fussing about him intercepting it.

I've been touch-typing for 40 years and using a Mac since 1984, and I'll mess with whatever I want.

There's no good reason Saul shouldn't do what works for him in this case – intercept Q OR W (or both for that matter).

On the other hand Rob's AppleScript above could be completely replaced with Keyboard Maestro actions, so Q could be escaped or allowed to continue.

Keyboard Maestro is pretty flexible.

-Chris