Plist Not Running AppleScript using launchctl

applescriptlaunchdplist

I am trying to schedule my AppleScript to run on 60 second intervals that runs two shell scripts and have appeared to setup my plist correctly as two files are outputted (StandardErrorPath and StandardOutPath) after 60 seconds elapse, but I don't see the results of my shell scripts appearing like they did when I ran the script in Script Editor. To me this appears to mean that the ProgramArguments section is not loading my AppleScript. Can anyone point me in the right direction? Should I add some type of logging to my AppleScript to log to the error file in my plist?

AppleScript file (Shell script runs correctly in Script Editor and Terminal):

do shell script "cd /Users/user/Desktop/Projects/node/webmasters-cli && /Users/user/.nvm/versions/node/v4.3.2/bin/node app.js DesktopUSA"
do shell script "cd /Users/user/Desktop/Projects/node/webmasters-cli && /Users/user/.nvm/versions/node/v4.3.2/bin/node app.js DesktopAll"

plist (Located in /Users/user/Library/LaunchAgents)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//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.webmasters.daily.pull</string>
    <key>KeepAlive</key>
    <false/>
    <key>RunAtLoad</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/user/Desktop/Projects/node/webmasters-cli/daily-api-call.scpt</string>
    </array>
    <key>StartInterval</key>
    <integer>60</integer>
    <key>StandardErrorPath</key>
    <string>/tmp/webmastersDailyTest.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/webmastersDailyTest.out</string>
</dict>
</plist>

Steps to load into launchctl:

1) Changed into directory

2) ran launchctl load com.user.webmasters.daily.pull.plist

3) Checked with launchctl list. plist appeared.

4) Checked /tmp and both StandardErrorPath and StandardOutPath files are created after 60 seconds. No values within files as expected.

Best Answer

Try adding /usr/bin/osascript as the first ProgramArguments. This will explicitly tell launchd to use the osascript to run your script.

Direct Approach

Do you need to use AppleScript for this launchd job? If not, you could avoid a level of abstraction by calling directly to node:

<key>WorkingDirectory</key>
<string>/Users/user/Desktop/Projects/node/webmasters-cli</string>
<key>ProgramArguments</key>
<array>
    <string>/Users/user/.nvm/versions/node/v4.3.2/bin/node</string>
    <string>app.js</string>
    <string>DesktopUSA</string>
</array>