2

Errors when getting phones

In Script Editor, if I run:

tell application "Contacts" to get the vcard of person 301

the result is:

"BEGIN:VCARD VERSION:3.0 PRODID:-//Apple Inc.//Mac OS X 10.13.6//EN
N:Bar;Foo;;; FN:Foo Bar
EMAIL;type=INTERNET;type=WORK;type=pref:foobar@gmail.com
TEL;type=HOME;type=VOICE;type=pref:555 555 1212
CATEGORIES:Address Book
UID:1e6e6e410a662666
X-ABUID:18B18941-E2B7-48CE-BB34-4A26CC0E23BB:ABPerson
END:VCARD
"

Note that this person has an email address and a phone number. If I run:

tell application "Contacts" to get the value of emails of person 301

the result is:

{"foobar@gmail.com"}

However if I run:

tell application "Contacts" to get the value of phones of person 301

I get

error "Contacts got an error: Can’t get value of every phone of person 301." number -1728 from value of every phone of person 301

and if I run

tell application "Contacts" to get the phones of person 301

error "Contacts got an error: AppleEvent handler failed." number -10000

What happens if the person doesn't have a phone number?

Edit: Based on one of the proposed answers to this post, I tried

tell application "Contacts"
    set thePhoneNumber to value of phones of people
end tell

which gave me something like

{missing value, {}, missing value, missing value, ...}

with a lot more "missing values" and "{}s" because I have about 2000 entries in the database.

Investigating this, I found that the "missing value" appears for people who have phone numbers, and the "{}" appears for people who do not have phone numbers. If I run the same command with "emails", I get a list of email addresses for each person who has emails, and an empty list "{}" for people who don't.


This is on Mac OS 10.13.6, Contacts 11.0 (1808.8).

Have I discovered a bug or is there something wrong with my script?

  • It's a bug in Contacts, which you could report to Apple (the more people that file bug reports, the more likely they are to prioritise fixing the issue). You might have to parse the vCard data yourself to retrieve the phone number. – CJK Sep 12 '18 at 17:29
  • 1
    @CJK thanks, I used bugreport.apple.com to submit a bug report. – highfalutin Sep 12 '18 at 21:28
-1

This should work for you...

tell application "Contacts"
    launch
    delay 1
    tell its person 301
        try
            set thePhoneNumber to value of phones
        end try
    end tell
end tell

This also works for me...

tell application "Contacts"
    set thePhoneNumber to value of phones of its person 301
end tell

You can also try running this following code

tell application "Contacts"
    set thePhoneNumber to value of phones of people
end tell

Then you will go to item 301 of that result and if there is no phone number... That may be why you are getting the error.

  • The result is still error -10000, "Contacts got an error: AppleEvent handler failed." – highfalutin Sep 9 '18 at 6:05
  • Updated the code to try that new version – wch1zpink Sep 9 '18 at 6:16
  • Unfortunately, @wch1zpink, the code still doesn't work on my machine. See the edits I made to my question. – highfalutin Sep 10 '18 at 4:03
  • I'm not quite sure what the problem is.I'm using the exact same operating system version and version of contacts. Did you try the second code sample in my answer? – wch1zpink Sep 12 '18 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .