I'm trying to accomplish the following with my tray app:
- MyApp.app should restart on crash
- MyApp.app should not launch on user-login (ie user has to manually start the app)
I have a problem that if user manually starts the app, then listing in
launchctl list com.myapp
doesn't show the running app.
If, however, I let the LaunchAgent launch app on user-login, then launchctl list com.myapp
properly shows the app, and will restarts it on crash (or any non-zero exit code).
Strangely enough, if user manually starts the app, launchd will try to launch it's own instance after several minutes. I can't even explain why this happens.
My LaunchAgent plist example:
<?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>
<dict>
<key>SuccessfulExit</key>
<false/>
<key>AfterInitialDemand</key>
<true/>
</dict>
<key>RunAtLoad</key>
<false/>
<key>Label</key>
<string>com.myapp</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/MyApp.app/Contents/MacOS/MyApp</string>
</array>
</dict>
</plist>