I am trying to create an applescript that will grab all of the labeled phone numbers of 'mobile' and 'iPhone' from the every contact in Contacts App (specifically the phone numbers from the iCloud account), and then send an iMessage or SMS to them using Messages App.

I think I have a good part of it, but I get 2 errors that I can't seem to understand.

tell application "Contacts"
    repeat with eachContact in (get every person)
        repeat with eachPhoneNum in (get phones of eachContact)
if label of eachPhoneNum is "mobile" or "iPhone" then
            delay 2

            tell application "Messages"
                set myid to get id of first service
                set theBuddy to buddy eachPhoneNum of service id myid
                send theMessage to theBuddy
            end tell
end if
        end repeat
    end repeat
end tell

Corrected Error 1: Contacts got an error: Can’t get label. As script is above.

Still experiencing Error 2: Can’t make «class az20» 1 of «class azf4» id "89E7AF18-A017-4119-B788-CBB96571FAAE:ABPerson" of application "Contacts" into the expected type.

  • Could you try to make a Minimal, Complete and Verifiable example that focuses on the problem that you are facing with the smallest amount of code possible?
    – grg
    Nov 27, 2014 at 18:54
  • @grgarside - Updated. The previous code was a verifiable, complete, working example, but I am more than happy to clean it up to make it 'minimal'. Thanks :) Nov 27, 2014 at 19:22
  • As of error 1, you're getting phone label 'mobile' and label 'iPhone '. Can't try it out right now as I'm on iOS...
    – Niko Nyman
    Nov 27, 2014 at 19:51
  • @NikoNyman Yes, when I strip out the label criteria, I get a class error that it can't convert the type. I am assuming this means that it can't convert the result of phone into the variable eachPhoneNumand needs some kind of conversion.. But I even tried adding as text to convert it, and I still get the error. Nov 27, 2014 at 20:20
  • I was a bit unclear previously: have you tried ...whose phone label is "mobile" or phone label is "iPhone"? To me it looks like you're getting the first error from trying to access label "iPhone" and (I assume) the property is called phone label.
    – Niko Nyman
    Nov 27, 2014 at 22:32


You must log in to answer this question.

Browse other questions tagged .