-- Hacked from two scripts from MacOSXHints.com -- http://www.macosxhints.com/article.php?story=20050208234638329 -- The code is a combination of the two scripts on that site, -- plus the urlencode routine from the site below -- I added a lot of comments to help me understand how this script works and how to make an Address Book plugin -- First script: http://www.macosxhints.com/dlfiles/google_map_scpt.txt -- Update script: http://homepage.mac.com/unixjunkie/.cv/unixjunkie/Public/Google%20Map%20Of.dmg.zip-link.zip -- by UnixJunkie (http://www.unixjunkie.net/) -- Second script: http://www.macosxhints.com/dlfiles/google_map_scpt2.txt -- by miked378 -- Set the property for the Google Maps URL property googleMaps : "http://maps.google.com/maps?q=" -- Set up Address Book using terms from application "Address Book" -- Tell Address Book to display this script when a ctrl-click is done on an address on action property return "address" end action property -- Tell Address Book to display the text below as the menu option on action title for aPerson with anAddress return "[New] Get a Google Map for " & name of aPerson end action title -- Tell Address Book to enable this action on should enable action for aPerson with anAddress return true end should enable action -- Tell Address Book what to do when the script is selected on perform action for aPerson with anAddress showMap(street of anAddress, zip of anAddress, city of anAddress, state of anAddress, country code of anAddress) end perform action end using terms from -- This is where the magic happens on showMap(street, zip, city, state) set addressURL to "" if zip is missing value then set addressURL to stripReturn(street) & ", " & city & ", " & state else set addressURL to stripReturn(street) & ", " & zip end if set addressURL to urlencode(addressURL) try tell application "firefox" OpenURL googleMaps & addressURL activate end tell on error error_message display dialog error_message buttons {"OK"} default button 1 end try end showMap -- Strip returns and everything after them on stripReturn(itemName) set returnChar to (ASCII character 10) if itemName contains returnChar then set AppleScript's text item delimiters to returnChar set itemName to itemName's text items set itemName to (the first item of itemName as string) end if set itemName to (itemName as string) end stripReturn -- urlencode is from: -- http://harvey.nu/applescript_url_encode_routine.html -- This safely encodes text so it can be used in a URL on urlencode(theText) set theTextEnc to "" repeat with eachChar in characters of theText set useChar to eachChar set eachCharNum to ASCII number of eachChar if eachCharNum = 32 then set useChar to "+" else if (eachCharNum ² 42) and (eachCharNum ³ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then set firstDig to round (eachCharNum / 16) rounding down set secondDig to eachCharNum mod 16 if firstDig > 9 then set aNum to firstDig + 55 set firstDig to ASCII character aNum end if if secondDig > 9 then set aNum to secondDig + 55 set secondDig to ASCII character aNum end if set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string set useChar to numHex end if set theTextEnc to theTextEnc & useChar as string end repeat return theTextEnc end urlencode