Is there any way to have Safari 5 (OS X) ask before exiting? I have fat fingers and often hit Command-Q when I want Command-W.
5 Answers
I remap Safari’s Quit menu item shortcut to ⌥⌘Q (Option-Command-Q) using the “Keyboard Shortcuts” tab of the “Keyboard & Mouse” preference panel in System Preferences.
- 42,029
As Scott noted in a comment, modern macOS versions have a checkbox labeled "Close windows when quitting an app" in the "General" section of System Preferences:

Unchecking that box will cause closed applications to remember their open windows and their content, and to reopen them when you restart the application.
Alternatively, if you prefer to enable this feature only for Safari, you can select "Safari opens with: All windows from last session" from the "General" tab in Safari preferences:

Note that this Safari-specific option is hidden when the general "Close windows when quitting an app" System Preferences option is unchecked, since it would be redundant in that case.
Also, as noted by Chris Johnsen, you can rebind the "Quit Safari" menu item to a different, less easily triggered keyboard shortcut (e.g. ⌥⌘Q) via System Preferences → Keyboard → Shortcuts → App Shortcuts:

Unfortunately, AFAIK there's no easy way to rebind the same shortcut for all apps, since the name of the menu item is obviously different for each app.
All screenshots taken and described behavior tested on macOS High Sierra version 10.13.4 with Safari 11.1. Obviously, later versions may change how things work.
- 1,851
Safari will prompt if you've edited a text field but not submitted the form yet.
Otherwise, you can get back to where you were after an accidental Quit by going to History > Reopen All Windows From Last Session.
- 110,156
In the tabs section of Safari's preferences, if you check the third option "Confirm before closing multiple tabs or windows", Safari will ask before exiting if you have more than one tab or window open. It won't ask for confirmation if you have only one open, but from what you're saying, that shouldn't be a major issue if you meant to close the window anyway.
- 5,993
Sayz Lim published a Keyboard Maestro macro that does the trick, just tried it out and love it: Warn Before Quitting Macro

- 39