• 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: Shane Stanley <email@hidden>
  • Date: Mon, 22 Sep 2014 10:14:23 +1000

On 22 Sep 2014, at 7:33 am, Bill Vlahos <email@hidden> wrote:

This script works to find every contact by name.
tell application "Contacts"
get name of first person whose name contains "Bill"
end tell

This script does NOT work to find every contact by phone number and results in the error below. What am I doing wrong?
tell application "Contacts"
get name of first person whose phone contains "805"
end tell

Name is a property, but phone is an element -- whose clauses only work with properties. A person can have more than one phone, and phones have values and labels, so you're going to have to do some looping. This should do what you want:

tell application "Contacts"
repeat with aPerson in people
set theNumbers to value of aPerson's phones
repeat with aNumber in theNumbers
if aNumber contains "805" then
return aPerson's name
end if
end repeat
end repeat
end tell


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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: Paul Berkowitz <email@hidden>
References: 
 >Search Contacts for phone number (From: Bill Vlahos <email@hidden>)

  • Prev by Date: Re: Can AppleScript determine if a shell process is running?
  • Next by Date: Re: Search Contacts for phone number
  • Previous by thread: Search Contacts for phone number
  • Next by thread: Re: Search Contacts for phone number
  • Index(es):
    • Date
    • Thread