Created
January 6, 2023 23:09
-
-
Save iloveitaly/37c49a147e622a14a8cacb1b44452f79 to your computer and use it in GitHub Desktop.
Hide and quit macOS applications in bash/zsh using AppleScript via osascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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