Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Created June 27, 2019 16:07
Show Gist options
  • Save talkingmoose/c1fd6e7fcec3000c9b2e590ae86c4de6 to your computer and use it in GitHub Desktop.
Save talkingmoose/c1fd6e7fcec3000c9b2e590ae86c4de6 to your computer and use it in GitHub Desktop.
Useful for killing all running applications that may prevent a restart for an upgrade. Killing apps does not allow for saving work. Use only as a last resort.
#!/bin/bash
# there's probably a better way to use lsappinfo to get the list of apps, but it's not well documented
appsList=$( /usr/bin/lsappinfo list | /usr/bin/grep -B 4 Foreground | /usr/bin/awk -F '\\) "|" ASN' 'NF > 1 { print $2 }' )
# kill each app by name except Finder
while IFS= read anApp
do
if [ "$anApp" != "Finder" ]; then
/usr/bin/pkill "$anApp"
echo "Killing app '$anApp'"
fi
done <<< "$appsList"
# wait a few second and kill Microsoft Error Reporting tool if it opens by killing a Microsoft app
sleep 3
/usr/bin/pkill "Microsoft Error Reporting"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment