【发布时间】:2015-01-01 16:07:33
【问题描述】:
所以这个小转移的目标是能够选择一段包含 URL 的文本,并让 OS X 使用 goo.gl URL 缩短服务将其转换为短 URL。
为此,我使用 Automator 创建了一个服务,该服务接受文本输入并将该输入传递给“运行 AppleScript”操作。下面列出了 AppleScript。
我已经安装了 node.js v0.10.33 并且还安装了一个名为 json (http://trentm.com/json/) 的节点包
只要我不将输出通过管道传输到 json 节点应用程序,下面的脚本就可以正常工作。
带有管道到 json 节点应用程序的 curl 命令在终端中完美运行。
我的猜测是 shell 环境关闭了,但我不知道如何调查。 有什么帮助吗?
-- shorten URLs via goo.gl URL shortener
-- syntax derrived from Scott Lowe @ blog.scottlowe.org
on run {input, parameters}
set curlCommand to "curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{\"longUrl\": \"" & input & "\"}' | /usr/local/bin/json id"
set jsonResult to (do shell script curlCommand)
return jsonResult
end run
【问题讨论】:
标签: node.js applescript osx-yosemite automator url-shortener