5

I need to create a package installer on OS X that handles the installation of two launched daemons: one that runs as root and one that runs as the current user. While this is just for a very small internal deployment, I can make no guarantees as to what the current username is. How can I either:

  • Make sure that the latter has the proper username set in the launchd plist file?

OR

  • Ensure that each one is setup by the proper invocation of launchctl, one that's using "sudo" and one that's not?
Anonymous
  • 1,750
  • 3
  • 16
  • 21

1 Answers1

3

In your postflight script just do something like this:

launchctl load -w /Library/LaunchDaemons/com.my.daemon.plist

LOGGEDUSERS=`who | awk '/console/ { print $1 }'`
for CURRUSER in $LOGGEDUSERS
do
    su -l $CURRUSER -c 'launchctl load /Library/LaunchAgents/com.my.agent.plist'
done

Take a look at this related question for some additional info

Community
  • 1
  • 1
cody
  • 3,233
  • 1
  • 22
  • 25