javascriptnode.jsmacosapplescript

Running JavaScript (using Node.js) with AppleScript?


In MacOS I have installed Node.js from the following link: http://nodejs.org/download/ (http://nodejs.org/dist/v0.10.29/node-v0.10.29.pkg).

I am using the following code in AppleScript:

do shell script "supervisor \"/Applications/xyz.js\""

But get the following error:

error "sh: supervisor: command not found" number 127

This works fine when run via Terminal like this:

supervisor /Applications/xyz.js


Solution

  • Sounds like your path enviroment variable is setup differently so that inside Applescript it cannot find the application.

    For example in applescript ....

    do shell script "echo $PATH"

    returns

    "/usr/bin:/bin:/usr/sbin:/sbin"

    But in terminal ...

    $ echo $PATH
    /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    

    So I'd just add the full path of the executable in applescript and that should fix the problem...

    do shell script "/path/to/app/supervisor ...."


    Here is an official explaination...

    The issue is that which application you tell determines the environment for the shell script — the working directory, environment variables, and so on. Most applications have the same environment, but relying on this is a maintenance risk. If your AppleScript is running in osascript, the working environment comes from the shell osascript was run from, which is completely separate from any other application.

    You can read more about it here

    https://developer.apple.com/library/mac/technotes/tn2065/_index.html