Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active December 24, 2021 16:33
Show Gist options
  • Save theoknock/1a4d5334489b905b57834d9589b021b6 to your computer and use it in GitHub Desktop.
Save theoknock/1a4d5334489b905b57834d9589b021b6 to your computer and use it in GitHub Desktop.
A keepalive script for Mac OS X apps, which takes the process name of the app as its only argument; recursively executes every one second to ensure the target app is still running (it also sets the input volume of the device to maximum)
# Continuously monitor the run state of an app
# identified by the specified name and
# launches the app if not running
while (true); do
ps_out=`ps -ef | grep $1 | grep -v 'grep' | grep -v $0`
result=$(echo $ps_out | grep "$1")
if [[ "$result" == "" ]]; then
open -a /Applications/AVS\ Server.app/
osascript -e "set volume input volume 100"
osascript <<END
tell application "Finder"
if exists application process "$1" then
set visible of application process "$1" to false
end if
end tell
END
fi
sleep 1
done
@theoknock
Copy link
Author

To execute:
./keepalive_process [process name]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment