0

I've coded my launch daemon and a launch agent for macOS. When the app is installed, I need to run both the daemon and the agent. I place the .plist for the deamon into /Library/LaunchDaemons and then run (as admin):

launchctl load /Library/LaunchDaemons/com.example.MyDaemon.plist

and since the plist has:

<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>

the daemon starts up right away.

But I'm struggling to do the same with my launch agent. Here's it's plist that I place into /Library/LaunchAgents directory for it to start for every user and also in the login screen:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LimitLoadToSessionType</key>
    <array>
        <string>Aqua</string>
        <string>LoginWindow</string>
    </array>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>com.example.MyAgent.plist</string>
    <key>Program</key>
    <string>/Library/PrivilegedHelperTools/com.example/MyAgent</string>
    <key>ProgramArguments</key>
    <array>
        <string>-d</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

when I try to run it as:

launchctl load /Library/LaunchAgents/com.example.MyAgent.plist

I get an error:

Warning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead. launchctl bootstrap is a recommended alternative. /Library/LaunchAgents/com.example.MyAgent.plist: Path had bad ownership/permissions Load failed: 122: Path had bad ownership/permissions

what am I doing wrong?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • "**since the command was ran as root**" Have you tried not running `launchctl` as root? Launch agents run in the context of a login session, so running as root is counter-productive. – pmdj Feb 09 '23 at 10:15
  • 1
    @pmdj In that case I'm getting: `Load failed: 5: Input/output error. Try running `launchctl bootstrap` as root for richer errors.` – c00000fd Feb 09 '23 at 11:19

0 Answers0