How Do I Export vCards from Apple Contacts using AppleScript?

Hey Troy,

Something's wrong.

How many contacts do you have?

It shouldn't have taken a whole minute to run, unless you have 5000 or more contacts.

And it certainly shouldn't have created a 1 byte file.

My first guess is that you haven't given Keyboard Maestro full disk access, but based on what you do I'd think it's not a good guess.

Run this from the Script Editor or Script Debugger, and let me know what you get.

tell application "Contacts"
   if not running then run
   return vcard of person 1
end tell

You can definitely write to a file with Keyboard Maestro?

-Chris

Hi Chris,
KM did not have full disk access, but it does now, and I restarted.
8,500 cards
Ran the script you provided, still 1 byte,
Text file attached.
thank you!!
Contact test.txt.zip (119.6 KB)

Hmm... I have no clue of why.

Try this more Keyboard Maestro native macro.

Backup Apple Contacts to a Date-Stamped VCF File v2.00.kmmacros (11 KB)

Macro-Image

Keyboard Maestro Export

That's what I would expect.

-Chris


MACRO ERROR OCCURRED on 2021-11-13 22:53:48


This info was pulled from the KM Engine Log for the

Last Macro error that occurred.

MACRO:


Backup Apple Contacts to a Date-Stamped VCF File v2.00


Action Type: Execute an AppleScript

Action Name: Extract vCard Text of All Contacts

ACTION ERROR: script error: text-script:148:153: execution error: Contacts got an error: AppleEvent timed out. (-1712).

KM Engine Log:


Execute an AppleScript failed with script error: text-script:148:153: execution error: Contacts got an error: AppleEvent timed out. (-1712). Macro “Backup Apple Contacts to a Date-Stamped VCF File v2.00” cancelled (while executing Extract vCard Text of All Contacts


Log File: ~/Library/Logs/Keyboard Maestro/Engine.log

Blubber...

Do you have copies of Script Debugger and BBEdit on your system?

-Chris

Yes, I have both -

Hi Chris, you are so generous with your time on this forum! Don't worry about this small fry issue. I'll simply use the select menu commands to export a full back up before I do an import. Really, I really appreciate your time and expertise

1 Like

It works, thank you very much.