Last active
June 12, 2017 17:43
-
-
Save geoffrepoli/83a12106de725da4d044fe4ff6492da9 to your computer and use it in GitHub Desktop.
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 | |
# geoff repoli | |
# customize this variable with relatively unique + identifiable string that matches the process(es) | |
# you want to terminate. not case-sensitive. for example: | |
# for all microsoft applications + background services: application="microsoft" | |
# for microsoft outlook: application="outlook" OR application="microsoft outlook" | |
application="your string goes here" | |
# get pids of any running microsoft processes | |
running_pid=$(pgrep -i "$application" 2>/dev/null) | |
# script only runs if processes are found | |
if [[ $running_pid ]]; then | |
# get the actual name of the process to display to the user | |
running_proc=$(ps -o comm= -p $running_pid | awk -F'/' '{print $NF}') | |
# creates an applescript dialog prompt telling the user which microsoft processes are running, and prompting them to click "OK" to allow the script to quit those apps | |
osascript <<-EOT | |
tell app "System Events" | |
set asWindow to display dialog "The following applications are running and must be closed before continuing:\n\n${running_proc}\n\nEnsure you have no unsaved work, then press OK to continue." with icon 0 buttons {"Cancel", "OK"} default button 2 | |
set asButton to button returned of asWindow | |
if asButton is "OK" then | |
do shell script "pkill -9 -f -i '$application'" | |
else | |
return | |
end if | |
end tell | |
EOT | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment