Description: This script will do a reverse look up on phone numbers
Requirement: Address Book Mac OS 10.3.x
-- Script Start (* http://www.macosxhints.com/article.php?story=20040105125520276 Multi-country/international ammended script Authored by: jolinwarren on Fri, Jan 23 '04 at 07:02AM Adapted for Sweden by Fredrik Jonsson, fredrik (at) combonet (dot) se home page <http://xdeb.org/wiki/AppleScript> *) using terms from application "Address Book" on action property return "phone" end action property on action title for aPerson with aPhone if (country of address 1 of aPerson) = missing value then return "Look up Sweden address" else return "Look up " & country of address 1 of aPerson & " address" end if end action title on should enable action for aPerson with aPhone if ((country of address 1 of aPerson) = "Sweden") or ¬ ((country of address 1 of aPerson) = "Sverige") or ¬ ((country of address 1 of aPerson) = "USA") or ¬ ((country of address 1 of aPerson) = missing value) then return true else return false end if end should enable action on perform action for aPerson with aPhone set phone_num to ((value of aPhone) as string) --handle look-ups for specific countries if ((country of address 1 of aPerson) = "Sweden") or ¬ ((country of address 1 of aPerson) = "Sverige") or ¬ ((country of address 1 of aPerson) = missing value) then if (the phone_num begins with "+") then set character_count to the number of characters of the phone_num set phone_num to "0" & (characters 4 thru (the character_count) of the phone_num) as string end if set phone_swe to the phone_num set phone_swe to my austauschen("(", "", phone_swe) set phone_swe to my austauschen(")", "", phone_swe) set phone_swe to my austauschen("-", "", phone_swe) set phone_swe to my austauschen(" ", "", phone_swe) set theURL to "http://privatpersoner.eniro.se/query?" & ¬ "firstname=&lastname=&area=&phone_number=" & ¬ phone_swe & ¬ "&what=wphone&firstnameType=trunc&lastnameType=trunc" & ¬ "&address=&addressType=trunc&zipcode=®ion=&advanced=" tell application "System Events" to open location theURL else if ((country of address 1 of aPerson) = "USA") then if (the phone_num begins with "+") then set character_count to the number of characters of the phone_num set phone_num to (characters 4 thru (the character_count) of the phone_num) as string end if if (label of aPhone) = "work" then set wpq to 0 else set wpq to 1 end if set orig_delim to AppleScript's text item delimiters set AppleScript's text item delimiters to {"(", ")", " ", "-"} try set qpa to (first word of phone_num) set qpx to (second word of phone_num) set qpp to (third word of phone_num) on error set AppleScript's text item delimiters to {"."} set theWords to text items of phone_num set qpa to (first item of theWords) set qpx to (second item of theWords) set qpp to (third item of theWords) end try set AppleScript's text item delimiters to the orig_delim set theURL to "http://ypng.infospace.com/home/yellow-pages/redir.htm?" & ¬ "qfm=p&searchtype=all&fromform=psearch&QK=10&top=1&" & ¬ "qcat=reverse&qsubcat=revphone&wqp=" & wpq & "&qpa=" & ¬ qpa & "&qpx=" & qpx & "&qpp=" & qpp & "&x=0&y=0" tell application "System Events" to open location theURL else if (country of address 1 of aPerson) = "Another Country" then --handle reverse lookup for "Another Country" here, etc... end if end perform action end using terms from (* Saschas fast search/replace routine for AppleScript searching and replacing in a string. This routine is my very own invention. So if you use it in your own scripts (that's OK with me!), then I want you to credit me within the source of your AppleScript and within any Readme-Files and Documentation your AppleScripts may have. (Just keep this comment in your script.) See how I did with David Cortrights great "getSelectedMessages" Routine? This routine is approx. > 300 times faster than searching replacing by looping through all the characters in a string. Author: Sascha Welter <swelter@mus.ch> *) on austauschen(suchen, ersetzen, theString) -- Parameters: search, replace, the String set olddelis to my text item delimiters set my text item delimiters to (suchen) tell me to set thelist to (every text item of theString) set my text item delimiters to (ersetzen) set theString to thelist as string set my text item delimiters to olddelis return theString end austauschen -- Script Stop