2014-07-01 91 views
0

当我运行以下命令逐一在终端它的工作原理和安装,MAC OS - Node.js的(NPM) - 通过AppleScript的具有管理员权限安装

须藤NPM安装主管


须藤NPM安装永远

它要求管理员密码在终端窗口并安装正常。

在我的AppleScript运行本作,

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 

它打开终端,并询问密码,并等待用户响应输入密码才能继续。我试过以下的AppleScript,

do shell script "sudo npm install supervisor" with administrator privileges 
do shell script "sudo npm install forever --global" with administrator privileges 

而且得到了以下错误,

错误 “命令:NPM:找不到命令” 1号

的AppleScript的需要索要普通密码输入用户名和密码对话框并运行,

sudo npm install su pervisor


须藤NPM安装永远

在终端不要求在终端窗口的密码。怎么做?

回答

1

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

shell脚本不默认情况下有你的路径导出到他们与苹果的脚本。另外,它们在shell中运行而不是默认的Terminal shell(很可能是bash)。在尝试运行苹果脚本时,应该包含npm(对我来说,/usr/local/bin/npm;请使用which npm)的完整路径而不是npm

但是,如果指定npm的完整路径,则会遇到另一个问题。 npm在路径中找不到node。我发现的解决方案是在苹果脚本中输出PATH

export PATH=$PATH:/usr/local/bin; sudo npm install forever

仔细检查/usr/local/bin同时包含nodenpm。这应该允许您成功安装而不提示。

+0

谢谢你工作完美。 –