views:

204

answers:

1

I have created Cocoa app which is type of launch agent. To distribute this I have created package as well which installs the app and copies the launchagnet plist file in /Libraries/LaunchAgents.

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.

Any suggestion how the agent registers itself to launchctl and runs in user context.

+3  A: 

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; see this mailing list post for more information.

Nicholas Riley
I tried this but this gives me error : "launch_msg(): socket is not connected".. any idea ?
Unicorn
It worked for me. You should only get that message if you're trying to install as a different user from the one who's logged in (http://lists.macosforge.org/pipermail/launchd-dev/2009-June/000553.html).
Nicholas Riley
I tried from terminal as well, by giving the user name directly instead of using env macro, getting same error. This is the only user who is currently logged in. Not sure what is going wrong. I think i might need to use logout after installation. Thanks for your help.
Unicorn
That's really strange - I don't know what to say, other than try posting on launchd-dev and/or filing a DTS incident. (Or just log out after installation. :-)
Nicholas Riley