AppleScript / Sending AppleEvents

My app wants to get the name of the frontmost window of another app, so I wrote a simple AppleScript to do that, which works fine in Script Editor.

When run from my Xojo app, the script initially resulted in a “Not authorized to send Apple events to System Events” error, so I added “NSAppleEventsUsageDescription” and “com.apple.security.automation.apple-events” items to my app’s Info.Plist.

I got a notification once (can’t remember if it was when running the debug or compiled app) and accepted.

The situation now is that my built app appears in System Settings > Privacy and Security > Automation, with “System Events” switched on, and my debug app appears in System Settings > Privacy and Security > Accessibility, and is switched on. When either the debug or built app is run, DebugLog shows

System Events got an error: myApp.debug is not allowed assistive access.

I’ve tried turning the Settings switches off and back on again, but haven’t been able to get a new prompt.

Any suggestions?

Check out my “runAS” example on how to deal with the lovely AppleScript security (Xojo + Alfred).

You can use tccutil to reset the permissions:

tccutil reset AppleEvents com.mothsoftware.mailarchiverx

I always do this before a release because I have foobared this repeatedly. Oh, and like full disk access the permissions only work in debug when you have a built app.

3 Likes