Skip to content

Instantly share code, notes, and snippets.

@thomasvanta
Forked from admsyn/README.txt
Last active September 6, 2015 18:40
Show Gist options
  • Save thomasvanta/17c8334df65237526b24 to your computer and use it in GitHub Desktop.
Save thomasvanta/17c8334df65237526b24 to your computer and use it in GitHub Desktop.
Keep an installation alive with launchd & launchctl
Add this .plist to ~/Library/LaunchAgents to have it automatically take effect whenever you log in. It will continue to be active until you log out (even if you delete the file).
You can take manual control over it instead by putting the file anywhere else, then using launchctl like this:
launchctl load com.admsyn.keep-twitter-alive.plist
and
launchctl unload com.admsyn.keep-twitter-alive.plist
Some notes :
- It will keep itself from rebooting the app repeatedly over a short period of time (e.g. if it crashes it will reboot instantly, if it crashes again right away it'll wait ~10 secs before trying again). I believe this is adjustable with another param in the plist.
- launchd "owns" the app it spawns this way, so if you open the app yourself, then load the .plist, you'll get two copies of the app running.
- Make sure the "Program" arg in the .plist points to the actual executable (e.g. in Contents/MacOS) instead of just the .app
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.admsyn.keep-twitter-alive</string>
<key>Program</key>
<string>/Applications/Twitter.app/Contents/MacOS/Twitter</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment