I've built an install using Apple's PackageMaker utility. It installs a daemon and a user agent. At the end of the install I would like to start the user agent using launchctl. However, since I had to elevate privileges during the install in order to install my daemon, I end up starting the user agent as root. If I use sudo -u <user> launchctl, I just get an error: "launch_msg(): Socket is not connected".
Is there any way to un-elevate privileges during an install?
# this just errors out with launch_msg(): Socket is not connected".
# sudo -u current_user /bin/launchctl load ""/Library/LaunchAgents/com.myuseragent.plist"
# this works but starts the user agent as root. I want it to run as the current user
/bin/launchctl load "/Library/LaunchAgents/com.myuseragent.plist"