退出时启动重新启动应用程序
我想知道如果用户未选择从顶部栏中选择“退出”,如何设置 Launchd 重新启动我的应用程序。 在某些情况下,应用程序可能会发生某些情况,并且可能会强制退出,并且如果选择了首选项,我希望它自动重新启动。 在在这里发帖之前我已经研究过它,并且我听说 Launchd 非常擅长做到这一点。 有人对如何实现它有任何建议吗?
谢谢你的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当应用程序运行时,让您的程序在用户的主文件夹中写入一个空的 .something 文件。 当应用程序正常退出时删除 .something 文件。
现在,您可以编写一个小脚本(AppleScript 或 shell 脚本)来检查您的应用程序是否正在运行,以及是否应该运行(通过检查 .something 文件)。 然后,如果需要,脚本可以重新启动应用程序。
您可以使用 launchd 安排脚本在启动时自动运行。
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.
您可以使用 KeepAlive 的 SuccessExit 设置仅在应用程序未正常退出时重新启动应用程序。 请参阅此 Mac OS X 提示条目,和/或 launchd.plist 手册页面,了解详细信息。
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.