从 NodeJS 中执行 osascript(AppleScript)
我知道我可能非常想念这一点,
但有人知道为什么这会不断返回错误吗?
$ node -v && node
v0.4.6
> var cmd = 'osascript -e "open location \"http://google.com\""';
> require('child_process').exec(cmd, function (error, stdout, stderr) { console.log(error); });
//Error message
> {
stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'Command failed: 15:20: syntax error: A “:” can’t go after this identifier. (-2740)\n',
killed: false,
code: 1,
signal: null
}
也许它与 cmd 中的双引号有关?
I know I am probably missing this hugely,
but anyone knows why this keeps returning an error?
$ node -v && node
v0.4.6
> var cmd = 'osascript -e "open location \"http://google.com\""';
> require('child_process').exec(cmd, function (error, stdout, stderr) { console.log(error); });
//Error message
> {
stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'Command failed: 15:20: syntax error: A “:” can’t go after this identifier. (-2740)\n',
killed: false,
code: 1,
signal: null
}
Perhaps it has something to do with the double quotes in the cmd
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能只是引用问题。这对我有用:
顺便说一句,如果您只想打开一个 URL,则无需通过 AppleScript。只需使用打开命令:
Probably just a quoting issue. This one works for me:
Btw, if you just want to open a URL, there is no need to go through AppleScript. Just use the open command:
这可以通过当前节点版本中的反引号
和 open 命令来简化
This is simplified through backticks in current node version
and for the open command