Skip to content

Instantly share code, notes, and snippets.

@hex2010
Last active October 6, 2016 07:22
Show Gist options
  • Save hex2010/5859c0ec2ec02c66000641836ba64dc7 to your computer and use it in GitHub Desktop.
Save hex2010/5859c0ec2ec02c66000641836ba64dc7 to your computer and use it in GitHub Desktop.
Auto relaunch specific application when it crash. (MacOS)
#!/bin/bash
# you can setup crontab to run this script periodically
# require pidof install in /usr/local/bin
# read config from ~/.bgapp
ret=0
while read s; do
IFS="|"; cfg=($s) ; unset IFS;
if [ "${#cfg[@]}" = "2" ]; then
if [ -z "`/usr/local/bin/pidof ${cfg[0]}`" ]; then
# echo "launch \"${cfg[0]}\": ${cfg[1]} &"
osascript -e "display notification \"launch \\\"${cfg[0]}\\\"\" with title \"bgapp\""
eval "${cfg[1]}"
fi
elif [ -n "$s" ]; then
echo "Invalid line in ~/.bgapp : \"\""
ret=1
fi
#echo $?
done < $HOME/.bgapp
exit $ret
# assume you place bgapp in $HOME/bin
* * * * * $HOME/bin/bgapp.sh
Spectacle|open -a Spectacle
BitBar|open -a BitBar
mongod|mongod --fork --syslog
godoc|nohup ~/bin/godoc -http=:12345 &
@hex2010
Copy link
Author

hex2010 commented Oct 1, 2016

for MacOS

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