Hi all,
I'm developing a sandboxed Mac OS app that generates and compiles AppleScript files to automate tasks in Pages (and other iWork apps). The app creates an AppleScript file and writes it to the NSApplicationScriptsDirectory (i.e., ~/Library/Application Scripts/com.example.app), then compiles and executes it via NSUserAppleScriptTask.
On Mac OS Ventura, however, I get the following error in the console when trying to write the file:
[PagesModifier] Error creating or compiling the script: You are not allowed to save the file "PagesModifier_...applescript" in the folder "com.example.app"
Here are my current entitlements:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.application-groups</key> <array/> <key>com.apple.security.automation.apple-events</key> <array> <string>com.apple.iWork.Pages</string> <string>com.apple.iWork.Numbers</string> <string>com.apple.iWork.Keynote</string> </array> <key>com.apple.security.files.user-selected.read-write</key> <true/> <key>com.apple.security.scripting-targets</key> <dict> <key>com.apple.iWork.Keynote</key> <array> <string>com.apple.iWork.Keynote</string> </array> <key>com.apple.iWork.Numbers</key> <array> <string>com.apple.iWork.Numbers</string> </array> <key>com.apple.iWork.Pages</key> <array> <string>com.apple.iWork.Pages</string> </array> </dict> <key>com.apple.security.temporary-exception.apple-events</key> <array> <string>com.apple.iWork.Pages</string> <string>com.apple.iWork.Numbers</string> <string>com.apple.iWork.Keynote</string> </array> <key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key> <array> <string>Library/Application Scripts/com.example.app</string> </array> </dict> </plist>
I suspect the issue might be due to sandbox restrictions on dynamically creating or modifying the Application Scripts directory on Ventura. Has anyone experienced something similar or have any suggestions on how to work around this?
Thanks in advance for your help!
Thanks for the explanation. And, given that, I think I have an easier path forward for you.
First up, ignore NSUserScriptTask
and it’s various subclasses. That infrastructure is designed for script attachment in an App Store app. A great example of that concept is the AppleScript support in Mail’s filtering rules. This is super cool, but it’s not a good match for your app.
Rather, I recommend that you run your scripts using NSAppleScript
. If you search the forums, you’ll find that I’ve posted a number of different examples of that tech in the past [1].
This will result in your app sending Apple events to the various iWork apps. By default, those are blocked by the App Sandbox. There are two ways around this:
-
Disable the sandbox completely.
-
Leave the sandbox enabled, but use temporary exception entitlements to open the required holes in the sandbox.
I talk about the second option in more detail in The Case for Sandboxing a Directly Distributed App.
Honestly, if I were you, building an app just for myself, I’d disable the sandbox and continue coding. But the choice is yours, and I’m happy to answer follow-up questions regardless of which path you take.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"