Over a weekend recently I built a tiny Mac app (more on that later). What I was trying to achieve required executing AppleScript, like so many things on macOS. It seemed simple enough, but of course new app sandboxing restrictions in macOS Mojave got in the way.
It is surprisingly easy to run AppleScript within a Mac app. All you need to do is create an instance of NSAppleScript. Swift’s multi-line string literals make it especially nice. You can write your script in the Script Editor, then copy it to your Swift source verbatim. AppleScript can be incredibly powerful and useful. I wrote this one to send my currently open Safari tabs to OmniFocus.
The first error in the Xcode console seemed completely unrelated to my app.
A temporary exception entitlement permits your macOS app to perform certain operations otherwise disallowed by App Sandbox.