swiftnsapplescript

Sending AppleEvent fails with sandbox


I try to show an element in the Calendar.app so the calendar is activated and the appropriate event is highlighted. I know how to do that but once Sandbox is on, I just get

Calendar got an error: A privilege violation occurred.

My code simply is this (not even trying to show an event but just reading one calendar):

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)
  }
}

And my Entitlements look like that:

<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>

I also tried with scripting bridge but that fails too (with less information but probably the same reason).


Solution

  • The failure of the entitlement com.apple.security.scripting-targets in Calendar.app seems to be a bug (even using tell application "Calendar" in the script).

    However the global temporary exception works:

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