I need to extract the phone number of all the contacts in a particular group and for that I am using the following code -

on run {input, parameters}  
    tell application "Contacts"
        set thePeople to every person
        repeat with i from 1 to number of items in thePeople
            set this_person to item i of thePeople
            set inGroup to name of group of this_person
            if inGroup is "Technology" then
                set x to properties of phones of this_person
            end if
        end repeat
    end tell
end run

But whenever I run the code, the script editor crashes and asks me to reopen it even though I have only one contact in that group. What's happening here?

  • did you test it with 'try' just to see if the behaviour is different? – Tetsujin Dec 24 '14 at 12:07
  • Can you elaborate? I am new to AppleScript. +Tetsujin – Samyak Dec 24 '14 at 12:40
  • you can isolate any part of an applescript so it attempts & doesn't error if it fails. Similar syntax to an if/end if, starts 'try' ends with 'end try'. Anything in between won't halt on error. May not work, but might allow you to hone down the problem section – Tetsujin Dec 24 '14 at 12:43


tell application "Contacts"
    set inGroup to first group whose name = "Technology"
    set phoneProps to properties of phones of inGroup's people
end tell
  • How do I retrieve only the phone number as an output instead of the label, class etc. – Samyak Dec 24 '14 at 14:24
  • set phoneProps to value of phones of inGroup's people – adayzdone Dec 24 '14 at 16:25
  • is the result a string? @aday – Samyak Dec 24 '14 at 16:29
  • No, a list of lists. – adayzdone Dec 24 '14 at 16:34
  • The element inside the lists? What type? – Samyak Dec 24 '14 at 16:35

You must log in to answer this question.

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