To quit Safari instead of closing its window

I have a Safari window on my Mac with multiple tabs. If I press Command-W or click the red Close button instead of pressing Command-Q, the next time I click the Safari icon in the Dock, the tabs are lost. (Yes, I can restore them by clicking “History” > “Reopen Last Closed window” or “Reopen All Windows from Last Session”, but this is too easy to forget when I’m in a hurry, which is my usual state.)

Is there a way (using Automator, Shortcuts, or something else) to automatically quit Safari (as if I’ve pressed Command-Q) once I press Command-W or click the red button? So that I don’t lose tabs anymore.

edit: Sorry, I need to correct my question. I don’t need to quit Safari when I press Command-W (because Command-W is normally used to close the current tab, and I don’t want to change this behavior, of course). I only need to quit Safari when I click the red Close button.

Not sure if this is what you want, but I use Command-H, hide, for that kind of thing.

1 Like

This is a nice trick, thanks.

1 Like

I don’t know how you’d go about closing tabs/windows with the keyboard with this enabled, but this Keyboard Maestro macro works:

1 Like

Wow, this is super interesting, many thanks! Could you explain where do I need to click in order to get the same as shown here?

Sorry, my original question was somewhat misleading. (I’ve just corrected it.)

I don’t need to quit Safari when I press Command-W (because Command-W is normally used to close the current tab, and I don’t want to change this behavior, of course). I only need to quit Safari when I click the red close button. Maybe you know a Keyboard Maestro solution for this as well?

1 Like

Bettertouchtool can do it. See this reddit thread:
https://www.reddit.com/r/MacOS/comments/m9kb9o/quit_application_with_red_x/

https://imgur.com/1ynuC3z

1 Like

Other options here. See post #3.

1 Like

Try the keyboard shortcut ⌘ M

BetterTouchTool works as expected. Many thanks, you have solved my problem!

1 Like