When I run the following commands one by one in Terminal it works and installs,
sudo npm install supervisor
sudo npm install forever
It asks for the admin password in Terminal window and installs fine.
In AppleScript I run this as,
tell application "Terminal"
do script "sudo npm install supervisor" in window 1
end tell
tell application "Terminal"
do script "sudo npm install forever --global" in window 1
end tell
It opens Terminal and asks the password and waits for user response to enter the password to continue. I tried the following AppleScript,
do shell script "sudo npm install supervisor" with administrator privileges
do shell script "sudo npm install forever --global" with administrator privileges
And got the following error,
error "sudo: npm: command not found" number 1
The AppleScript needs to ask for the password once in the common enter the username and password dialog and run the,
sudo npm install supervisor
sudo npm install forever
In Terminal without asking for password in Terminal window. How to do it?
https://developer.apple.com/library/mac/technotes/tn2065/_index.html
Shell scripts do not by default have your path exported into them with apple script. In addition, they are run in shell instead of your default Terminal shell (most likely bash). You should include the full path to
npm(/usr/local/bin/npmfor me; find usingwhich npm) instead of justnpmwhen trying to run an apple script.However, when you specify the full path to
npm, you run into another problem.npmcan't findnodein the path. The solution I found to work was to exportPATHin the apple script.export PATH=$PATH:/usr/local/bin; sudo npm install foreverDouble check that
/usr/local/bincontains bothnodeandnpm. This should allow you to successfully install without being prompted.