'Why won't LaunchAgents run my Automator app?

I'd like to run an app I created via Automator every 5 minutes, so I placed the following com.user.wilson.plist file in this folder:

/Library/LaunchAgents

<?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>Label</key>
    <string>com.user.wilson</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/open</string>
        <string>-a</string>
        <string>/Users/paul/Documents/Wilson/Script/mt-wilson-background_app</string>
    </array>
   <key>StartInterval</key>
   <integer>300</integer>
</dict>
</plist>

Then, I loaded it using the following command in the terminal:

launchctl load Library/LaunchAgents/com.user.wilson.plist

but for some reason, the app never runs.

I can, however, successfully run the app using this command:

/usr/bin/open -a /Users/paul/Documents/Wilson/Script/mt-wilson-background_app

Any ideas why the .plist file won't do what I'm expecting it to?



Solution 1:[1]

In order to see what's going wrong, you can add a log file in your plist like this:

<?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>Label</key>
    <string>com.user.wilson</string>
    <key>StandardErrorPath</key>
    <string>/Users/paul/Documents/Wilson/Script/err.log</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/open</string>
        <string>-a</string>
        <string>/Users/paul/Documents/Wilson/Script/mt-wilson-background_app</string>
    </array>
   <key>StartInterval</key>
   <integer>300</integer>
</dict>
</plist>

Note: For the modifications to take effect, unload and load again:

launchctl unload Library/LaunchAgents/com.user.wilson.plist
launchctl load Library/LaunchAgents/com.user.wilson.plist

Typically, if the err.log says it can't find your app, it means it's a permission issue.

I would suggest you try to move your app from /Users/paul/Documents/Wilson/Script/mt-wilson-background_app to /Users/paul/Documents/mt-wilson-background_app

Then update your plist accordingly, unload an reload your plist, is it working better now?

Solution 2:[2]

I ran into nearly the exact same problem. I finally (FINALLY!!!) found a cure that worked for me.

Originally, the broken version of the .plist launch agent that wouldn't run no matter what I tried was in /Library/LaunchAgents. Moving the agent to /Users/[me]/LaunchAgents eliminated the "Application Not Running" error.

It seems counterintuitive since the root agent should be able to run everything from any location, but I can only guess that AppleScript's check to see if an app is running or not is user account-dependent somehow. I'm betting there's something you can add to the AppleScript to actually fix this the "right" way, but this works well enough for me, so I'm taking the win.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 sstringer