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.