使用沙箱发送 AppleEvent 失败

Sending AppleEvent fails with sandbox

我尝试在 Calendar.app 中显示一个元素,以便激活日历并突出显示相应的事件。我知道该怎么做,但是一旦 Sandbox 打开,我就会得到

Calendar got an error: A privilege violation occurred.

我的代码就是这样(甚至不尝试显示事件,只是阅读一个日历):

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
  func applicationDidFinishLaunching(aNotification: NSNotification) {
    let source = "tell application \"iCal\"\n set theCalendar to first calendar whose name = \"test\"\nend tell"
    let scriptObject = NSAppleScript(source: source)
    var errorDict: NSDictionary? = nil
    _ = scriptObject!.executeAndReturnError(&errorDict)
    print (errorDict)
  }
}

我的权利看起来像这样:

<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
  <key>com.apple.security.scripting-targets</key>
  <dict>
    <key>com.apple.ical</key>
    <array>
      <string>com.apple.ical.read</string>
    </array>
  </dict>
</dict>

我也尝试过脚本桥,但也失败了(信息较少,但可能是同样的原因)。

Calendar.app 中授权 com.apple.security.scripting-targets 的失败似乎是一个错误(即使在脚本中使用 tell application "Calendar")。

但是全局临时异常有效:

<key>com.apple.security.temporary-exception.apple-events</key>
<array>
  <string>com.apple.ical</string>
</array>