Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created January 6, 2023 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/37c49a147e622a14a8cacb1b44452f79 to your computer and use it in GitHub Desktop.
Save iloveitaly/37c49a147e622a14a8cacb1b44452f79 to your computer and use it in GitHub Desktop.
Hide and quit macOS applications in bash/zsh using AppleScript via osascript
function quit_apps() {
for app in $@; do
echo "Quitting $app..."
osascript -e "with timeout of 30 seconds
quit app \"$app\"
end timeout"
if [ $? -ne 0 ]; then
# if the application did not quit on it's own, let's force it!
killall "$app"
fi
done
}
function hide_apps() {
for app in $@; do
echo "Hiding $app..."
osascript -e "tell application \"System Events\"
set visible of application process \"$app\" to false
end tell"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment