macoscocoacontactsabaddressbookappkit

Programmatically launching OS X's Contacts app showing a contact?


Let's say that I've just created an ABPerson record and managed to save it in the user's address book. How do I programmatically open the default application which handles the address book (which most likely is Contacts but in some cases it might be Outlook or some other app) and show the new address book record I've just added?

Thanks in advance.


Solution

  • The addressbook URL scheme is able to show the person record or edit it:

    ABPerson * aPerson = <#assume this exists#>;
    
    // Open the Contacts app, showing the person record.
    NSString * urlString = [NSString stringWithFormat:@"addressbook://%@", [aPerson uniqueId]];
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
    

    More information is in Address Book Programming Guide.