2

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!

Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94
  • `UID` is not a command that `Adress Book` understands and that is why AppleScript treats it as a variable and generates that error since no variable with that name is defined. Maybe "id" works. –  May 26 '15 at 00:43
  • So how can I search based on that `UID` property, though? – Rushy Panchal May 26 '15 at 00:44
  • @Zero This was from a Yahoo contact that was imported from Facebook, so that might be where – Rushy Panchal May 26 '15 at 00:52

1 Answers1

3

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.

Jerry Stratton
  • 3,287
  • 1
  • 22
  • 30