macosplistautomatorlaunchd

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

  • 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?