Can a custom label be applied to a contact field using partial text from the field value

applescriptcontacts.app

In the Contacts app in OS X Yosemite it is currently impossible to import custom field labels when importing from a CSV file. I use a 3rd party app to manage my contacts and I would like to import the custom labels that I use for postal addresses, phone numbers and email addresses for my contacts.

If I create a field that merges the custom label with field data, and a separator character in between, would it be possible to use an AppleScript to extract the custom label, remove the separator character, and rename the field with the custom label?

For example, I currently have a custom label for a phone field:

Field Custom Label: Dad Mobile

Field Value: 123 456 7890

Merged Field: Dad Mobile;123 456 7890

When importing the file into Contacts via CSV I would map it to "phone other". So the phone field for the contact would look like this when imported:

other: Dad Mobile;123 456 7890

Again, the script would extract the custom label, remove the separator character and rename the field with the custom label, resulting in:

Dad Mobile: 123 456 7890

I am somewhat new to scripting.

Best Answer

Applescript to Create Contacts:

    set phoneDad to "Dad Mobile" --Use your own custom variables imported from CSV
-- would need to parse CSV

    tell application "Contacts"

        set thePerson to make new person with properties ¬
            {first name:"John", last name:"Doe", organization:"ABC Apps"} ¬


        -- see the "Contacts" AppleScript dictionary
        -- for other attributes than may be added

        make new email at end of emails of thePerson with properties ¬
            {label:"Work", value:"john@example.com"}
        make new phone at end of phones of thePerson with properties ¬
            {label:phoneDad, value:"555.555.1212"} --Use a variable to replace hardcoded number
        make new url at end of urls of thePerson with properties ¬
            {label:"Work", value:"http://www.example.com/"}     
        save

    end tell

You can set custom variables based on your CSV parsing.

This should point you in the right direction. So, in answer to your question, with Applescript you can add custom fields. Just use a similar syntax to the above code. You just need to parse your CSV files accordingly. I don't know what 3rd party app you use, but this is routinely done directly from database apps such as Filemaker.

Contacts

Further reading: vCard Wikipedia

vCard 3.0

BEGIN:VCARD VERSION:3.0 N:Gump;Forrest;;Mr. FN:Forrest Gump ORG:Bubba Gump Shrimp Co. TITLE:Shrimp Man PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif TEL;TYPE=WORK,VOICE:(111) 555-1212 TEL;TYPE=HOME,VOICE:(404) 555-1212 ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America LABEL;TYPE=WORK:100 Waters Edge\nBaytown\, LA 30314\nUnited States of Ameri ca ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America LABEL;TYPE=HOME:42 Plantation St.\nBaytown\, LA 30314\nUnited States of Ame rica EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com REV:2008-04-24T19:52:43Z END:VCARD