Rushy Panchal
Rushy Panchal

Reputation: 17532

Search a custom property

I am using AppleScript to search through a bunch of my contacts, with a specific (custom) property.

Here is my code:

tell application "Address Book"
    set allPeople to every person whose last name = "CERTAIN_LAST_NAME"
    get properties of item 1 of allPeople
end tell

The specific last name is just a person who I knew had that specific property.

And the (trimmed) output:

CATEGORIES:Contacts
UID:{MY_EMAIL_ADDRESS}:426
X-ABUID:SOME_ID_TAG:ABPerson
END:VCARD

I want to find everyone who contains the property UID with the value of {MY_EMAIL_ADDRESS}:some_number. I'm very new to OS X and AppleScript to so I'm not really sure what to do. I searched for a way to filter my contacts based on a custom property, with:

tell application "Address Book"
    set allPeople to every person whose UID = "{MY_EMAIL_ADDRESS}:426"
    get properties of item 1 of allPeople
end tell

But this gave me this error:

my_script.scpt:69:72: execution error: The variable UID is not defined. (-2753)

I appreciate any help with this issue!

Upvotes: 2

Views: 183

Answers (1)

Jerry Stratton
Jerry Stratton

Reputation: 3466

The reason you can’t find UID is because it doesn’t exist as a field, even in your data. If you look at the bottom of the snippet you provided, it says “END:VCARD”. If you look up through the snipped text, you should see “vcard:"BEGIN:VCARD”.

The field that contains this text is vcard, and you can search through that.

tell application "Address Book"
    set allPeople to every person whose vcard contains "UID:{YOUR_EMAIL_ADDRESS}:426"
    get properties of item 1 of allPeople
end tell

I don’t have your values, of course, but I was able to do a search on cards that contained known values of UID in my own contacts.

Upvotes: 3

Related Questions