Skip to content

Instantly share code, notes, and snippets.

@haircut
Created February 8, 2017 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save haircut/59e6e3f690c95f38f38ff38c2cfaa3da to your computer and use it in GitHub Desktop.
Save haircut/59e6e3f690c95f38f38ff38c2cfaa3da to your computer and use it in GitHub Desktop.
Closes all running apps, excluding those found in a customizable whitelist
#!/bin/sh
# Quit apps command
read -r -d '' OSASCRIPT_COMMAND <<EOD
set white_list to {"Finder"}
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
try
tell application this_process
quit saving no
end tell
on error
# do nothing
end try
end if
end repeat
EOD
/usr/bin/osascript -e "${OSASCRIPT_COMMAND}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment