The opinions on this site are my own, and are not necessarily shared by my employer.
Loading LaunchAgents as root
25 Mar 2017
There are times when you will need to load a LaunchAgent when a script is running as root - when you are running a postinstall script from a package or when you are loading the LaunchAgent via your management tool of choice (Puppet, Munki, Jamf Pro), for example.
All of these example are assuming you have a LaunchAgent at /Library/LaunchAgents/com.company.example.plist.
Loading a LaunchAgent
Unloading a LaunchAgent
The Python version may look more complicated, but is slightly more robust as it is retrieving the current username using Apple’s frameworks and I have also allowed for the script not to fail if there isn’t a user logged in.