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


Click here to return to the 'A version of the script for Yahoo Maps' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A version of the script for Yahoo Maps
Authored by: bryang on Nov 16, '03 01:19:42PM
I use Yahoo for mapping. Here's a script that almost works. For some reason I can't get the submit to work, but it does fill in the address, city, state, and zip. Also, I haven't tested the country stuff, so it may not work perfectly either.


-- Script adds the abilty to load the selected address in maps.yahoo.com
using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for aPerson with anAddress
		return "Map with Yahoo"
	end action title
	
	on should enable action for aPerson with anAddress
		return true
	end should enable action
	
	on perform action for aPerson with anAddress
		my showMap(street of anAddress, zip of anAddress, city of anAddress, ¬
			state of anAddress, country code of anAddress)
	end perform action
	
end using terms from

on showMap(street, zip, city, state, country)
	tell application "Safari"
		activate
		open location "http://maps.yahoo.com"
		
		(* Wait till maps.yahoo.com is loaded in the webbrowser *)
		my waitForLoading(60)
		set map_doc to document 1
		
		(* Fill in the text fields *)
		do JavaScript "document.mapForm2.addr.value = \"" & ¬
			street & "\"" in map_doc
		do JavaScript "document.mapForm2.csz.value = \"" & city & ", " & state & " " & zip & ¬
			"\"" in map_doc
		
		(* Find the country and select it *)
		set nbOfCountries to do JavaScript ¬
			"document.mapForm2.country.options.length" in map_doc
		repeat with i from 1 to nbOfCountries
			set iValue to do JavaScript ¬
				"document.mapForm2.country.options[" & i - 1 & "].value" in map_doc
			if iValue is country then
				set theIndex to i - 1
				exit repeat
			end if
		end repeat
		do JavaScript "document.mapForm2.country.options[" & ¬
			theIndex & "].selected = 1" in map_doc
		
		(* Submit the request *)
		do JavaScript "document.mapForm2.submit()" in map_doc
	end tell
end showMap

on waitForLoading(timeoutValue)
	tell application "Safari"
		delay 4
		repeat with i from 1 to timeoutValue
			delay 1
			if (do JavaScript "document.readyState" in document 1) is "complete" then
				exit repeat
			end if
		end repeat
	end tell
end waitForLoading




[ Reply to This | # ]