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


Click here to return to the '10.3: Integrate maporama.com maps in Address Book' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Integrate maporama.com maps in Address Book
Authored by: aranor on Nov 16, '03 05:56:01PM
I've spent a bit of time customizing this script. It doesn't use JavaScript anymore and it doesn't do anything like automatically filling out a form and submitting it. Instead, it passes all the information directly in as GET parameters in the URL. Basically, it works much better than the script in the hint :) Here it is:

using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for aPerson with anAddress
		return "Maporama"
	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)
	-- Create GET string for maporama
	-- COUNTRYCODE _XgoGCAddress Zip State _XgoGCTownName
	if country is missing value then
		set countryCode to "US"
	else
		set countryCode to toUpper(country)
	end if
	set getStr to "COUNTRYCODE=" & encode_text(countryCode) & ¬
		"&_XgoGCAddress=" & encode_text(street) & ¬
		"&Zip=" & encode_text(zip) & ¬
		"&State=" & encode_text(state) & ¬
		"&_XgoGCTownName=" & encode_text(city)
	
	tell application "Safari"
		activate
		open location "http://www.maporama.com/share/map.asp?" & getStr
	end tell
end showMap

-- this sub-routine is used to encode text 
on encode_text(this_text)
	set the acceptable_characters to "abcdefghijklmnopqrstuvwxyz0123456789_"
	set the character_list to {}
	repeat with this_char in this_text
		set this_char to the contents of this_char
		if this_char is in the acceptable_characters then
			set the end of the character_list to this_char
		else if this_char is " " then
			set the end of the character_list to "+"
		else
			set the end of the character_list to encode_char(this_char)
		end if
	end repeat
	return (the character_list) as string
end encode_text

-- this sub-routine is used to encode a character 
on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char

-- this sub-routine uppercases a string
on toUpper(this_text)
	set character_list to {}
	repeat with this_char in this_text
		set this_char to the contents of this_char
		set the ASCII_num to (the ASCII number this_char)
		if ASCII_num ? 97 and ASCII_num ? 122 then
			set ASCII_num to ASCII_num - 32
		end if
		set this_char to (the ASCII character ASCII_num)
		set the end of the character_list to this_char
	end repeat
	return (the character_list) as string
end toUpper


[ Reply to This | # ]
10.3: Integrate maporama.com maps in Address Book
Authored by: BradW on Nov 16, '03 07:26:44PM

Sorry to ask such a basic question, but your script won't compile on my system because of this line:

if ASCII_num ? 97 and ASCII_num ? 122 then

(8 or so lines from the end of the script). The problem seems to be the ?, and I'm wondering if I'm displaying the web site in a font that swapped out a special character that's used in scripts. The error I'm getting has to do with "expecting a then," but now that I want to report it exactly, I can't get it to display again.

BradW



[ Reply to This | # ]
10.3: Integrate maporama.com maps in Address Book
Authored by: aranor on Nov 16, '03 08:11:55PM

Hrm. I typed it as >= and <= but it must have turned them into the actual greater-than-or-equal-to and less-than-or-equal-to chars (option-, and option-.)



[ Reply to This | # ]
10.3: Integrate maporama.com maps in Address Book
Authored by: aranor on Nov 16, '03 08:40:53PM
If anybody wants an applescript link for this directly, the latest entry on my blog has a link.

[ Reply to This | # ]