• 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: Christopher Stone <email@hidden>
  • Date: Sat, 27 Sep 2014 10:05:43 -0500

On Sep 27, 2014, at 03:37, Axel Luttgens <email@hidden> wrote:
Anyway, here's an additional approach, supposed to let Contacts do all the hard work:

tell application "Contacts"
   people whose (class of (first phone whose value contains "805") is phone)
end tell
______________________________________________________________________

Hey Axel,

I bow...  That is absolutely bitchin'!  :)

I've used Axel's code to create a name/number report of all people who have a phone number with an area code of "###" or "(###)".

-------------------------------------------------------------------------------------------
set areaCode to "405"
tell application "Contacts"
  set {nameList, phoneList} to {name, value of phone} of (people whose (class of (first phone whose value starts with areaCode or value starts with "(" & areaCode & ")") is phone))
end tell
set recoList to {}
repeat with i from 1 to length of nameList
  item i of phoneList
  set end of recoList to {item i of nameList, item i of phoneList, ""}
end repeat
set AppleScript's text item delimiters to linefeed
recoList as text
-------------------------------------------------------------------------------------------

Now, let's play with that a bit.

I believe the OP was trying to find a single contact based on an incoming phone number.

-------------------------------------------------------------------------------------------
set phoneNum to "###-####"
tell application "Contacts"
  set foundReco to people whose (class of (first phone whose value contains phoneNum) is phone)
  if length of foundReco = 1 then
    set selection to item 1 of foundReco
  end if
end tell
-------------------------------------------------------------------------------------------

I'm leaving off the area code due to inconsistencies in how Contacts deals with it.

On my 10.9.5 system I have a mixture of ###-###-####, (###) ###-###, and ########## numbers.

If I let Contacts auto-format an phone number when I enter it the number seems to always be fouled up when AppleScript gets it even if it displays correctly in Contacts.  I need to test more, but this sure seems to be a bug.

Hell.  I forgot the you can't get a card to display if it is not in the selected group, and there's not a means to select "All Contacts".  LaunchBar somehow manages to do it though, so there is some method available.  Does anyone know how to do this?

--

This one creates a more comprehensive report of found items.

-------------------------------------------------------------------------------------------
set phoneNum to "###-####"
set recoList to {}
tell application "Contacts"
  set foundReco to {name, value of phone, formatted address of its address} of (people whose (class of (first phone whose value contains phoneNum) is phone))
end tell

repeat with i from 1 to length of item 1 of foundReco
  repeat with n in foundReco
    set end of recoList to item i of n
  end repeat
  set end of recoList to ""
end repeat

set AppleScript's text item delimiters to linefeed
set recoList to recoList as text
set AppleScript's text item delimiters to linefeed & linefeed & linefeed
set recoList to text items of recoList
set AppleScript's text item delimiters to linefeed & linefeed
set recoList to recoList as text
-------------------------------------------------------------------------------------------

Okay.  I've had enough of that for a while.  :)

--
Take Care,
Chris

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

  • Prev by Date: Re: Simple finder window sort worked in mountain lion but not in Mavericks
  • Next by Date: Re: Search Contacts for phone number
  • Previous by thread: Re: Search Contacts for phone number
  • Next by thread: Re: Search Contacts for phone number
  • Index(es):
    • Date
    • Thread