Mac OS - 使用 launchctl 将应用程序添加到自动启动
我可以像这样使用 launchctl 启动应用程序: launchctl Submit -l ProgramName -- open -g -b com.company.ProgramName 效果很好!我可以杀死应用程序,即使它崩溃了,它也会重新运行。
但是当我注销或重新启动 Mac 时,我的进程不再运行。或者,在某些情况下,它不是以 ProgramName (这是我的应用程序名称)运行,而是以 ProgramName.app/Contents/MacOS/program_name 中的可执行文件名称运行,
plist 文件就是这种情况。我运行命令 launchctl -w /Users/my_username/Library/LaunchAgents 并且进程工作正常!但重启后就看不到了。
我更喜欢第一种加载进程的方法,有什么建议为什么进程在重新启动后不会自动加载吗?
I can start application with launchctl like this: launchctl submit -l ProgramName -- open -g -b com.company.ProgramName and it works great! I can kill app, and it'll re-run again even if it crashes.
But when i logout or reboot Mac, my process is no longer run. Or, in some cases, it runs not with ProgramName (whitch is my application name), but with name of executable file in ProgramName.app/Contents/MacOS/program_name
Such situation with plist files. I run command launchctl -w /Users/my_username/Library/LaunchAgents and process works fine! But after restart i can't see it.
I prefer first method to load processes, any suggestions why process doesn't autoload after reboot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您需要将“RunAtLoad”设置为“true”,以便在用户登录时启动您的应用程序。
但是使用“submit”时无法从命令行设置 RunAtLoad。至少在我网上查到的launchctl.c版本中没有。
看起来您必须使用“load”创建一个 .plist 文件,而不是使用“submit”。
更烦人的是launchctl的“加载”,不能将stdin作为.plist文件名的输入,无论是无参数还是名称“-”。遗憾的是,也许launchctl的开发者不是来自Unix背景。这意味着您被迫将短暂的文件散布在文件系统的某个位置,至少在加载它之前是这样。
I believe you need to set "RunAtLoad" to "true" for it to start your application when user logs in.
But there is no way to set RunAtLoad from command-line when using "submit". At least not in the version of launchctl.c that I checked online.
It looks like you have to create a .plist file with "load", instead of using "submit".
What is more annoying is that launchctl's "load", can not take stdin as input to .plist filename, either with no-argument, or name "-". Shame, perhaps the developers of launchctl are not from Unix background. This means you are forced to litter your short-lived file somewhere on the file-system, at least until you have it loaded.