Keyboard Maestro is "Not Authorized to Send Apple Events to Contacts" on Monterey

This AppleScript will export each contact to its own vCard in the folder ~/Action/vCards/ :

set vPath to (path to the home folder as string) & "Action:vCards"
alias vPath

tell application "Contacts"
	repeat with cardPerson in people
		set nameOfvCard to name of cardPerson & ".vcf"
		set outFile to (open for access file (vPath & ":" & nameOfvCard) with write permission)
		write (vcard of cardPerson as text) to outFile
		close access outFile
	end repeat
	quit
end tell

But when I tried to run it in Keyboard Maestro, I get the following error:

2021-11-18 04:02:25 Action 12588 failed: Execute an AppleScript failed with script error: text-script:109:364: execution error: Not authorized to send Apple events to Contacts. (-1743)

2021-11-18 04:02:25 Execute an AppleScript failed with script error: text-script:109:364: execution error: Not authorized to send Apple events to Contacts. (-1743). Macro “Export vCards @daily” cancelled (while executing Execute AppleScript).

There does not seem to be a way to add Keyboard Maestro to the "Contacts" section of System Preferences, as shown here:

It appears that it is supposed to "just work" (except when it doesn't).

I wondered if anyone knew why this might be, and if there was a work-around.

1 Like

Strange,
keyboard maestro does appear in contact in my case.
image

Ooh, I wonder if it's because I said no to the newsletter that @peternlewis offers when I registered the app.

Peter: Any help appreciated. Do I need to reinstall Keyboard Maestro ? How do I let it prompt me for Contacts access again?

You (probably?) need to enable Automation control of Contacts by Keyboard Maestro Engine.

Any script you run in Keyboard Maestro that communicates via AppleScript with another application will require Keyboard Maestro Engine to have Automation permission to control that application.

Hey TJ,

You're on what version of macOS?

When I was fooling with Big Sur on your mini, I was having terrible problems with permissions dialogs flashing by and not giving me the chance to interact with them.

-Chris

That was it! Thanks! I didn't think to look there when there was another setting for contacts.

Oh, Apple … your security is good intentioned, but that road leads us to the opposite direction of heaven :wink:

2 Likes

This is Monterey on the Mini, but it's been completely wiped and a clean install done since then.

Also I'm pretty sure those issues were due, at least in part, to both of us being logged in at the same time, which I think macOS "supports" but does not get a lot of Q&A done on it!

1 Like

I did have trouble on the Mini, but I misspoke – I meant the MacBook Air.

I had a bunch of troubles with Big Sur. I don't know if you were logged in concurrently with me or not.

I haven't tried with Monterey as yet.

-Chris