Here is my launchd script to keep SomeApp always running.
Name it SomeApp.restart.plist
and place it in ~/Library/LaunchAgents/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>SomeApp.restart</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/SomeApp.app/Contents/MacOS/SomeApp</string>
</array>
</dict>
</plist>
Load it once with
launchctl load ~/Library/LaunchAgents/SomeApp.restart.plist
Launchctl will run this after reboots.
- RunAtLoad will launch the application the first time launchctl runs this
- KeepAlive will restart it if the application quits (CMD+Q or crash)
Should run forever. If you want a GUI tool to help, Lingon works even though development has stopped.