Preventing accidentally quitting an app with a cool alert box!

I thought this would be helpful to anyone who accidentally quits apps.

Step one:

In BTT, go to the Keyboard shorcuts tab (or press ⌘ + 4). Make a new shortcut, using ⌘Q.

Step two:

Make the trigger 'Run AppleScript (blocking), and paste in this code:

tell application "System Events" to set FrontmostApp to name of application processes whose frontmost is true

display alert "⌘Q
Are you sure that you want to quit " & FrontmostApp & "?" message "______________________

Any unsaved changes will be lost." as critical buttons {"Quit all Apps", "Yes", "No"} default button 2 cancel button "No"

if the button returned of the result is "yes" then
	tell application (path to frontmost application as text) to quit
	
else if the button returned of the result is "Quit all Apps" then
	-- get list of open apps
	tell application "System Events"
		set allApps to displayed name of (every process whose background only is false or frontmost is true) as list
	end tell
	
	-- leave some apps open 
	set exclusions to {"Finder", "BetterTouchTool"}
	
	-- quit each app
	repeat with thisApp in allApps
		set thisApp to thisApp as text
		if thisApp is not in exclusions then
			tell application thisApp to quit
		end if
	end repeat
	
end if

Aaaand there you have it. Now, when you press ⌘Q to quit an app, an alert box will appear with the options 'Yes' (to quit), 'No' (to not quit) and 'Quit all apps' (to quit all apps except Finder and BetterTouchTool).

Thanks