Not authorized to send Apple events to Mail

I’m using the AppleScript that @MacSparky posted last year (?) a lot.
Suddenly it stopped working on my iMac, but still does work on my Macbook Pro.
Any clue what causes the message:‘Not authorized to send Apple events to Mail.’?
It runs through a TextExpander snippet which is synced between the 2 computers.

Any ideas are welcome.

Does the script still run okay from the native script editor? That could help narrow down if it is TextExpander that would need the permission.

Yes, it works in the native script editor.

Ok, so TextExpander specific, and likely that app isn’t asking for the permission.

I think when it does so, the Mail app should appear under the Preferences > Security & Privacy > Privacy > Automation > TextExpander settings. I just don’t know if TextExpander is set-up to prompt for this (I do use TextExpander, but not Mail.app).

At one point you could use a utility to push things in via the command line, but security restrictions have (rightly) locked that down. I don’t think there’s a way around that except to get Smile to add something in; though maybe some other way does exist that someone else can suggest?

You can of course reset the Apple Events permissions database via the command line.

tccutil reset AppleEvents

But if TextExpander doesn’t ask for permission, then you’re a few steps back as you’ll have to reauthorise everything. However if TextExpander does support asking for the permission, this is the right way to proceed.

As a workaround, I’m wondering if you could save your AppleScript, and then use a shell script in TextExpander to call it via osascript? I think that could put it into the realm of indirect access and so it wouldn’t be TextExpander asking for access, but your shell. Might be worth a try :man_shrugging:t2:

Thanks,

TextExpander seems to be authorized on my iMac…

Okay, might be worth trying the permissions reset then.

I did reset the Apple Events permissions database with the command you provided.
The result is the same. Still the error message in TextExpander. In the script editor it works. Textexapnader is not asking for authorization…

Sounds like that’s worth raising as a query with Smile’s support and showing both screenshots.

Did the workaround I suggested work?

To be honest the osascript is a bridge too far to get it working for me.
I added a keyboard maestro action to my magic key stroke and removed the one from TextExpander. It now works from KM instead of TextExpander.
It works again. Thanks for the support @sylumer!

Hi @RobU,

I’m having a similar issue with a Script that accesses reminders. I have indications in the console that running my script via osascript on the command line uses “indirect access” (which runs MUCH slower than from Script Editor) and hits timeouts unless I increase the timeout time). In Script Editor, it reliably takes about 40 seconds. Via osascript (i.e. indirect access), it sometimes takes 6 minutes. More often than not though, it hits the new 10 minute timeout I set.

I’m wondering about your KM work-around. Does it go through “indirect access” according to the console logs? And I’m wondering if I can assign my script as a Quick Action, set a keyboard shortcut, and launch it via another script that uses a kaystroke… because it’s a synch of my reminders to a json file in order to allow me to code a reminder completion event trigger for automations…