简体   繁体   中英

Launchd Relaunch App on Quit

I am wondering how to set Launchd to relaunch my app if the user has not chosen to choose "Quit" from the top bar. There are cases where something may happen to the app, and it may force quit, and if a preference is selected I want it to relaunch automatically. I have looked into it before posting here, and I have heard that Launchd would be pretty good at doing this. Does anyone have any advice about how to accomplish it?

Thanks for any help.

Let your program write an empty .something file in the user's home folder when the app is running. Remove the .something file when the application quits normally. Now you could write a little script (AppleScript or shell script) that checks if your app is running and in case it is not if it should (by checking the .something file). The script can then, if needed restart the app. You can schedule the script to run automatically at startup using launchd.

You can use the SuccessfulExit setting of KeepAlive to only relaunch the app if it didn't quit normally. See this Mac OS X Hints entry , and/or the launchd.plist man page, for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM