Slightly OT: AppleScript to open Contact Address?

Well yes, in a way this question could be better placed in an AppleScript forum. But maybe some of you encountered a similar problem before:

Do you know if there is a way to open Mac OS’ Contacts and tell it to show a certain person retrieved from a Xojo app? I can read and add to Contacts and found out how to install and communicate with an AppleScript, but I cannot figure out how to “show” a certain entry – there seems to be no show command, and setting the selection to some properties doesn’t work. I try to avoid creating a complete contact window in Xojo when Contacts can do this fine, but currently it seems to me I’ll have to in order to show all the details – or is there another way to convince Contacts into cooperation?

As always a lot of thanks in advance!

Contacts (formerly Address Book) has a custom URL handler for the addressbook:// URI space.
I don’t recall the syntax to show a contact card but I believe you can find this in Apple Developer Library. If I remember properly, you must get the UniqueID of a person and use this in the URL.
I already used this in past (it’s working since Mac OS X 10.4 at least), and you don’t need AppleScript, just the ShowURL() method from Xojo. Additionally, I’m certain you can add a &edit parameter to the URL to show the contact card in edit mode.

Thanks for the hint, Massimo! That’s a clue I’ll follow soon.

To make the forum more workable as a programming dictionary (in case someone else searches for this topic), here’s the link to the URL scheme:

EDIT - I edited so everyone could SEE the URL

Hmm, but it doesn’t work for me. The following opens Contacts, but it will not show the currently selected person. Any ideas?

if CallData.CallerPhoneBookContact<>NIL then 
  dim s as string = "addressbook://%@"+CallData.CallerPhoneBookContact.UniqueID

end if

You don’t need to include the “%@“ in the string. This is the formatting placeholder for the NSString’s stringWithFormat method from which you copied (Objective-C language).


Did I write already I never got accustomed to C syntax?

Works like a charm without it. Thanks a lot, Massimo!