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
|