How do I have Safari 6 ask before quitting (to avoid accidental quits)?

Solution 1:

The setting was called "Confirm before closing multiple tabs or windows", but it was removed in 10.7 when Resume was introduced. defaults write com.apple.Safari ConfirmClosingMultiplePages -bool true doesn't work anymore either.

The part of Resume where application state is kept after quitting was disabled by default in 10.8, but you can reenable it from the General preference pane:

You can also enable it in just Safari by running defaults write com.apple.Safari NSQuitAlwaysKeepsWindows -bool true and quitting and reopening Safari.

Safari will still reload tabs when they are restored. And restoring state has only worked about half of the time for me since Safari 6 or 10.8.

You might also change the shortcut for quitting Safari:

Or disable some of the shortcuts completely:

defaults write com.apple.Safari NSUserKeyEquivalents -dict 'Quit Safari' '\0' 'Close Window' '\0' 'Close All Windows' '\0'

Solution 2:

In the History menu, you have the new option to "Restore last window closed" on top of the previously existing "Restore all windows from previous session".

Solution 3:

The fact that Safari doesn't "ask" before closing when multiple tabs exist: 1. Not "asking" is a nuisance. My spouse, who is not too tech davy, never seems to notice that there are multiple tabs open. She just clicks the close button, generally intending to close only the active tab. 2. Even when there is just one tab in use, it should be possible to close using the little gray x in the tab as is done for each tab when there is more than one. That would make things self-consistant. One then could close tabs, one by one, including the last one which would result in the whole window being closed (the same as when the red x is clicked). 3. For those who don't like to receive a warning, let them have a way within Safari Preferences to opt out. But the default should be to warn.

Making things self-consistant is the most compelling of all reasons. It's good design practice, folks.