为什么单击 Applescript 通知会打开 AppleScript 编辑器?

为什么单击 Applescript 通知会打开 AppleScript 编辑器?

我正在尝试使用 AppleScript 和 Python。但我现在遇到的大问题并不是关于 Python 的。最终目标是能够编写使用 AppleScript 功能的 Python 脚本。在执行此操作时,我会在 AppleScript、命令行和 IDLE 中进行测试。

如果我输入:

osascript -e 'display notification "Lorem ipsum dolor sit amet"'

在终端中的 bash 中运行它,我收到一个 Growl 通知,但当我单击它时,Applescript 编辑器会打开。如果它已打开但未处于活动状态,它将变为活动应用程序。如果我创建以下 AppleScript 文件:

on run display notification "This is a notice." end run

并从终端使用 osascript 运行它,当我单击 Growl 通知时,脚本编辑器会打开。当我在 Python 中使用 osascript 运行相同命令时,也会发生同样的事情。

换句话说,如果我使用 AppleScript 发布 Growl 通知,它总是会打开 AppleScript 编辑器。

(我已在线尝试了许多示例脚本,并且看来,在某个时候,也许是随着 Mavericks 的出现,Applescript 和 Growl 的许多规则发生了变化,因为许多脚本在剪切、粘贴和保存后将不再起作用。)

(我使用的是 OS X 10.9.4。)

为什么会打开脚本编辑器?我该怎么做才能阻止这种情况?

答案1

似乎你不能轻易停止脚本编辑器的打开https://discussions.apple.com/thread/6449168

因此看起来你最好使用终端通知程序,我刚刚测试过它甚至可以在 mavericks beta 上使用:

ProductName:    Mac OS X
ProductVersion: 10.10
BuildVersion:   14A299l

https://github.com/alloy/terminal-notifier

尽管 10.10 有新版本的 ruby​​,但第一种安装方法仍然有效:

 sudo gem install terminal-notifier

但是 brew install terminal-notifier 警告:

$ brew install terminal-notifier
terminal-notifier: A full installation of Xcode.app is required to compile this software.
Installing just the Command Line Tools is not sufficient.
Xcode can be installed from the App Store.
Error: An unsatisfied requirement failed this build.

到目前为止,我在 brew 中想要的所有功能都只需要命令行工具,因此我将避免使用 Xcode,除非我需要某些功能只能通过 Xdode 获得。目前还没有;-)

相关内容