简体   繁体   中英

MAC OS - Running JavaScript (using Node.js) with AppleScript?

In my MAC OS 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 ).

This is because I need to run a JavaScript on Google Chrome. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM