Global LaunchAgent implementation on macOS

208 views Asked by At

I have been trying to implemented a working global launch agent which can work across multiple users, but I cannot get it to the finish line. It is working for a single user perfectly but when switched to a different user the launch agent is failing with exit code 78 - function not implemented and cannot understand anything from the error. below is my plist

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.my.company.agent</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>-c</string>
        <string>/Applications/MyApp.app/Contents/Resources/runscript.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

I have placed the launch agent at /Library/LaunchAgents/com.my.company.agent.plist and when I run ls -al /Library/LaunchAgents/com.my.company.agent.plist, I get -rw-r--r-- 1 root wheel 752 Jan 21 13:27 /Library/LaunchAgents/com.my.company.agent.plist

The permissions of the /Library/LaunchAgents are drwxr-xr-x 8 root wheel 256 Jan 21 13:32 /Library/LaunchAgents

I am using this command to load the agent /bin/launchctl load /Library/LaunchAgents/com.my.company.agent.plist

When I run ls -al /Applications/MyApp.app/Contents/Resources/runscript.sh, I get -rwxr-xr-x 1 root wheel 227 Jan 21 13:28 /Applications/MyApp.app/Contents/Resources/runscript.sh.

The content of the runscript.sh is

#! /bin/sh
osascript <<EOF
tell application "Calendar"
   activate
end tell
EOF

Entire configuration seems fine as per other stackoverlfow recommendations, and the launch agent works great on the first user, but as soon as I try to load it from the second user it is failing with 78 exit code, I really appreciate your input, thanks.

0

There are 0 answers