Start a launch agent as user?

howie_isaacks
Valued Contributor II

I'm working on a new post install script for Nudge. Delivering Nudge settings using a profile has not been as reliable as I would like it to be. I found Dan Snelson's Nudge post install script (https://github.com/dan-snelson/Nudge-Post-install/wiki) and it has been a good starting point. Its command to load the launch agent doesn't work. My understanding is that we need to use Launchctl bootstrap instead of Launchctl load as we did with older versions of macOS. I have other scripts that load launch daemons that use bootstrap/bootout. These work well. Since a launch agent loads when a user logs in, it's different. What is the proper command to load a launch agent using a script deployed by Jamf Pro? If I can get this one thing to work, it pretty much wraps up getting this done. 

1 ACCEPTED SOLUTION

RaGL
New Contributor III

For LaunchAgents, I'm always using the following pattern:

#!/bin/bash

Name_loggedInUser=$(stat -f %Su /dev/console)
UID_loggedInUser=$(id -u $Name_loggedInUser)

launchctl bootstrap gui/$UID_loggedInUser <path to LaunchAgent plist>

 

View solution in original post

1 REPLY 1

RaGL
New Contributor III

For LaunchAgents, I'm always using the following pattern:

#!/bin/bash

Name_loggedInUser=$(stat -f %Su /dev/console)
UID_loggedInUser=$(id -u $Name_loggedInUser)

launchctl bootstrap gui/$UID_loggedInUser <path to LaunchAgent plist>