John Gruber wrote this simple, but useful AppleScript that warns you when quitting Safari if there are multiple tabs open. His post suggests how to implement this with FastScripts, but I wanted to use it with Keyboard Maestro, so here's how you do it:
One: Copy the script from the Daring Fireball post.
Two: Make a new Group in Keyboard Maestro that only activates when inside Safari.
Three: Make a new Macro that activates on the keyboard shortcut “Cmd+Q”.
Now you should have something like this:
Now when you hit Cmd+Q in Safari, it will make you confirm the action. Done!