• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Search Contacts for phone number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Search Contacts for phone number


  • Subject: Re: Search Contacts for phone number
  • From: Nigel Garvey <email@hidden>
  • Date: Mon, 22 Sep 2014 09:53:40 +0100

Paul Berkowitz wrote on Sun, 21 Sep 2014 18:41:43 -0700:

>If the same person has several phone numbers containing "805" (such as
>anyone living in the area code where I reside myself), you'll get his
or her
>name several times. You can take care of that this way:.
>
>set peopleList to {}
>tell application "Contacts"
>    repeat with aPerson in people
>        set theNumbers to value of aPerson's phones
>        repeat with aNumber in theNumbers
>            repeat with aNumber in theNumbers
>                if aNumber contains "805" then
>                    set end of peopleList to aPerson's name
>                    exit repeat
>                end if
>            end repeat
>        end repeat
>    end repeat
>end tell
>return peopleList

A faster variation would be to dump all the relevant data to the script
in one go and to do the search in the resulting lists rather than keep
referring to the application. Luckily, Contacts allows such dumps. (But
I don't have the Yosemite version to check.)

  tell application "Contacts"
    set {allNames, allNumbers} to {name, value of phones} of people
  end tell

  set peopleList to {}
  repeat with i from 1 to (count allNames)
    set theNumbers to item i of allNumbers
    repeat with aNumber in theNumbers
      if aNumber contains "805" then
        set end of peopleList to item i of allNames
        exit repeat
      end if
    end repeat
  end repeat

  return peopleList


NG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: Search Contacts for phone number
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: A permission problem?
  • Next by Date: Re: Search Contacts for phone number
  • Previous by thread: Re: Definitions and Class error Re: Search Contacts for phone number
  • Next by thread: Re: Search Contacts for phone number
  • Index(es):
    • Date
    • Thread