MacOS – How to load a LaunchAgent always as root

launchdmacos

I'm using a LaunchAgent to always open a cocoa application (i.e. Xcode) at login. the custom application requires root permission but when it's loaded by launchctl is loaded without permissions.

How can i do it?

I already tried using the "UserName" keyword in the Agent's plits, but doesn't work.

Best Answer

LaunchAgents are always run by the user that logs in, and therefore don't obtain root privileges.

/Library/LaunchDaemons are run by root and therefore gain root privileges when they are run. Place your .plist here instead and it will run as root, however it won't be run when the user logs in, as it's run by root not the user that is logging in.