Last active
April 15, 2022 20:59
-
-
Save mikez/483462dbf1783af4b0fd96c98d473eed to your computer and use it in GitHub Desktop.
Close all apps except the frontmost visible one. macOS only.
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
#!/bin/bash | |
# get frontmost app | |
frontmost_app=$(osascript -e ' | |
tell application "System Events" | |
POSIX path of (file of application processes whose frontmost is true and visible is true) | |
end tell | |
') | |
escaped_frontmost_app=${frontmost_app//\//\\/} | |
# write automator workflow to temporary file | |
tmpfile=$(mktemp) | |
plutil -convert xml1 -o "$tmpfile" - <<END | |
{ | |
"actions": [{ | |
"action": { | |
"ActionParameters": { | |
"appException": false, | |
"fileNames": ["$escaped_frontmost_app"], | |
"saveChanges": true | |
}, | |
"ActionBundlePath":"\/System\/Library\/Automator\/Quit All Applications.action" | |
} | |
}] | |
} | |
END | |
# run automator | |
automator "$tmpfile" | |
# cleanup | |
rm "$tmpfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you know a more elegant way, I'm curious! I tried to access the parameters directly in Automator; without luck.