I'm writing an installer for my launch daemon, and for a launch agent, that will run in every logged in user session on macOS. The installer will be running as an admin, and thus I can install and start my launch daemon as such:
launchctl load /Library/LaunchDaemons/com.example.MyDaemon.plist
and stop it as such:
launchctl unload /Library/LaunchDaemons/com.example.MyDaemon.plist
The issue is that I need to run (and stop) my launch agent right after installation (and un-installation) in every logged in user session, as it doesn't seem to happen automatically until I log off and log back in.
I placed my launch agent into:
/Library/LaunchAgents/com.example.MyAgent.plist
But how do I start/stop it from a root user process?
PS. Both plists have RunAtLoad
and KeepAlive
set to true
.