所以这个小改道的目标是能够选择一段包含URL的文本,并使用goo.gl URL缩短器服务让OS X将其转换为短URL。如何让这个applescript工作?
为此,我使用Automator创建了一个服务,该服务接受文本输入并将该输入传递给“运行AppleScript”操作。下面列出了AppleScript。
我已经安装的node.js v0.10.33也安装了一个节点包叫做JSON(http://trentm.com/json/)
下面的脚本工作得很好,只要我不用管输出到JSON节点的应用程序。
卷曲命令与管道到json节点应用程序在终端工作完美。
我的猜测是与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
谢谢,我会检查一下。对于我自己的熏陶,我想知道为什么我写的版本不起作用 - 但是当我有*更多的时间时,我可以用它来破解它:) – 2014-11-09 23:15:58
这个作品非常完美。谢谢! – 2014-11-09 23:20:27