简体   繁体   English

可可启动代理在安装后进行注册

[英]Cocoa Launch agent registering itself after installation

I have created Cocoa app which is type of launch agent. 我已经创建了启动代理类型的Cocoa应用。 To distribute this I have created package as well which installs the app and copies the launchagnet plist file in /Libraries/LaunchAgents. 为了分发此文件,我还创建了一个软件包,该软件包可安装应用程序并在/ Libraries / LaunchAgents中复制launchagnet plist文件。

Now the problem is after installation i want this app to be running in user context immediately without logoff/restart. 现在的问题是安装后,我希望此应用程序可以在用户上下文中立即运行而无需注销/重新启动。 If I register this with "launchctl" from installer, using post install script, it run in root context, as installer is running in root context. 如果我使用安装后脚本向安装程序的“ launchctl”注册了此文件,则它将在根上下文中运行,因为安装程序在根上下文中运行。

Any suggestion how the agent registers itself to launchctl and runs in user context. 任何有关代理如何将自身注册到launchctl并在用户上下文中运行的建议。

Try this in the postinstall script: 在安装后脚本中尝试以下操作:

/usr/bin/sudo -u $USER /bin/launchctl load -S Aqua /Library/LaunchAgents/com.yourcompany.launchagent.plist

Note that if multiple users are logged in via Fast User Switching, this will only activate your launch agent for the user who installed it. 请注意,如果通过快速用户切换登录了多个用户,则只会为安装它的用户激活启动代理。

There is an unsupported way to make this work with multiple users logged in on Mac OS X 10.5/10.6, using launchctl bsexec ; 有一种不受支持的方法,可以使多个用户使用launchctl bsexec在Mac OS X 10.5 / 10.6上launchctl bsexec see this mailing list post for more information. 看到这个以获取更多信息邮件列表的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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