Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Multi-country/international ammended script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Multi-country/international ammended script
Authored by: jolinwarren on Jan 23, '04 07:02:14AM
I took the "Infospace" version of the reverse look-up script by "hughescr" and modified it to provide the following:

  • Displays the country name where the address will be searched for.
  • Disables the menu item if the country is unsupported.
  • Allows for adding different search methods for different countries.
  • Uses the System's default web browser instead of always using Safari.
  • Allows for the use of '.' as a number separator (as in '212.345.3456').

Note that currently, this script only performs reverse look-ups for US phone numbers. To add support for other countries, simply add to the end of the script where it says "handle reverse lookup for Another Country here, etc...". Right now, if no country is specified on an address card, the script defaults to the USA. This can also be changed in the script. Enjoy!


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 USA 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) = "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 thephone to ((value of aPhone) as string)
		set wpq to 1
		if (label of aPhone) = "work" then
			set wpq to 0
		end if
		set origDelim to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {"(", ")", " ", "-"}
		try
			set qpa to (first word of thephone)
			set qpx to (second word of thephone)
			set qpp to (third word of thephone)
			
		on error
			set AppleScript's text item delimiters to {"."}
			set theWords to text items of thephone
			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 origDelim
		
		--handle look-ups for specific countries
		if ((country of address 1 of aPerson) = "USA") or ¬
			((country of address 1 of aPerson) = missing value) then
			
			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


[ Reply to This | # ]