Sandbox entitlement to script iTunes via NSAppleScript
After contacting the Developer Technical Support of Apple, I was able to solve this problem, which is actually 2 problems in one.
First, the entitlements need to have the bundle identifiers properly cased. For iTunes, the entitlements must be like this (note the capital T
in iTunes):
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.iTunes</key>
<array>
<string>com.apple.iTunes.library.read-write</string>
</array>
</dict>
Then, the privilege violation will occur unless the AppleScript code includes of source 1
at the end like this :
tell application "iTunes" to add (POSIX file "your/path/to/mp3.mp3") to library playlist 1 of source 1
There you go!
NSAppleScript execution fails in sandboxed app
Turns out the problem was using the bundle id com.apple.Safari in the entitlements, instead of com.apple.safari.
Is there an App store entitlement for NSAppleScript(source: do shell script \sudo commands?
you can't do that if the app is sandboxed, arbitrary script execution is forbidden by the sandbox. No sudo
allowed.
AppleScripting sandboxed app from another sandboxed app using ScriptingBridge
I filed a tech support incident with Apple about this, and they confirmed that it is a bug. The only workaround they suggested is to hold onto the (valid) instance of SketchApplication
returned by the first call to -applicationWithBundleIdentifier:
when Sketch is running for later use. This is not really a viable workaround at all in my particular case since the target app is very likely to already be running before the scripting app is launched.
I've filed a radar for this: rdar://27625862.
The other option is to use the com.apple.security.temporary-exception.apple-events
sandbox entitlement. I'll do that for now, and hope that I can justify its use for app store review.
Sending AppleEvent fails with sandbox
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>
[NSAppleScript executeAndReturnError:] gives error with script that works in AppleScript Editor
It was one of those stupid mistakes that I figured out while my mind worked on it in the background while I worked at other things.
Sandbox. The app is sandboxed and the entitlements give it access to iTunes Apple Events, but I hadn't added QuickTime Player entitlement. The testing app I built wasn't sandboxed, which was why it worked fine.
Related Topics
Extending Dictionary with Key and Value Constraints
Swiftui - Form with Error Message on Button Press and Navigation
Automatic Select a Date in Datepicker in Swift Language
Swiftui Conditional View Transitions Are Not Working
Turn Off Splash Screen When Using Flutterviewcontroller Within Existing Native App
Uislider Handle Changes Width on Different Size Ipads
Why Run Loop Is Needed When Using Dispatchqueue.Main.Async in MAC Command Line Tool in Swift
Find Index of Annotation Mapkit
Overlaying Image on Video Reduces Video Resolution
How to Instantiate a View Controller Programatically, Without Storyboard
Swift: Handling an Unexpected Nil Value, When Variable Is Not Optional
How to Get Parallax Effect on UIbutton in Tvos
Nssavepannel - How to Restrict User to Only Save One One Set Directory
Issue with Optional Core Data Relationship Using Nspersistentcloudkitcontainer
How to Set .Realm File on Realm
Syntax to Create Dictionary in Swift
Arkit: Plot a Node at a Specific Pixel at a Specific Z Distance from Camera