您可以在 Mac OS X 上从 shell 脚本访问 AppleScript API 吗?
我已经在 Mac 上使用 shell 脚本做了很多工作,但我讨厌 AppleScript,并且我希望能够以其他方式访问 Mac 应用程序的 API。有谁知道任何其他方法来获得 AppleScript 的强大功能,而无需忍受其可怕的语法和贫乏的文档(以及它的缓慢,如果可能的话)的痛苦?
I already do a lot with shell scripts on the Mac, but I loathe AppleScript, and I would love to be able to access Mac apps' APIs in some other way. Does anyone know any other way to get the power of AppleScript without the pain of its horrible syntax and meager documentation (and its slowness, if possible)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
appscript 可能是您最好的选择 - Python 或 Ruby 有一些变体,它们应该很适合 shell 脚本。
在处理单个应用程序的词汇表时仍然会遇到一些尝试和错误,您对此无能为力,但至少您将拥有一种功能更强大的语言(或两种)来解决它。
appscript is probably your best bet - there are variants for Python or Ruby which should fit well into shell scripts.
There'll still be some trial and error in dealing with individual applications' vocabularies, which you can't really do much about, but at least you'll have a far more capable language (or two) to wrap around it.
MacRuby 怎么样?它不完全是 shell 脚本,但到目前为止还没有被删除(而且,可以说,更好)。
也不确定具体的 Applescript API(未检查),但使用 HotCocoa 你基本上有获取可可。
我已经从这里捏了这个代码片段,但是你可以看到它非常可读(这是只是为了显示 hello world 窗口的代码,诚然不是典型的脚本操作):
警告 - MacRuby 版本为 v0.6,但在我有限的使用范围内通常是稳定的。不完全符合您的要求,但无论如何可能值得一看。
What about MacRuby? It isn't exactly shell scripting but it's not so far removed (and, arguably, much nicer).
Also not sure about the Applescript APIs specifically (not checked) but with HotCocoa you basically have access to Cocoa.
I've pinched this code snippet from here but as you can see it is very readable (this is code just to display a hello world window, admittedly not a typical scripting operation):
Caveat - MacRuby is at v0.6 but is generally stable in my limited usage. Not exactly what you asked for but might be worth a look anyway.