Created
November 24, 2012 15:45
-
-
Save admsyn/4140204 to your computer and use it in GitHub Desktop.
Keep an installation alive with launchd & launchctl
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
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 path/to/the/plist/com.admsyn.keep-twitter-alive.plist | |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
and | |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
launchctl unload path/to/the/plist/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 |
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
<?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> |
This is great, thanks! I'd like to add that if anyone is running into issues where their application performs noticable worse when launched using launchd, it may help to set the ProcessType tag to Interactive:
<key>ProcessType</key>
<string>Interactive</string>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks a ton, this is perfect.