Skip to content

Instantly share code, notes, and snippets.

@ffub
Created May 9, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffub/fb1364c11ca4f64bccb935d620ee3371 to your computer and use it in GitHub Desktop.
Save ffub/fb1364c11ca4f64bccb935d620ee3371 to your computer and use it in GitHub Desktop.
Quit all applications on a Mac, with the option to leave the front most open
-- get list of open apps
tell application "System Events"
set allApps to displayed name of (every process whose background only is false) as list
set activeApp to name of first application process whose frontmost is true
set exclusions to {"Finder", "LaunchBar"}
end tell
set {button returned:myQuery} to display dialog "Which applications do you want to quit?" with title "Quit All" with icon caution buttons {"Cancel", "Quit All", "Keep Active Open"}
if myQuery is "Quit All" then
-- quit each unless exclusion
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
else if myQuery is "Keep Active Open" then
-- quit each unless exclusion
copy activeApp to end of exclusions
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment