For those of us how want to use googlemaps instead of mapquest and/or want a 1-click "get me from home to address" do the following:
1) Go to http://farha.com/GMAP/ and download the two files at the bottom of that entry. rename the files fromk .txt to .scpt and copy into ~/Library/Address Book Plug-Ins/ (~ is your home folder for example niels)
2) If the above link does work then copy/paste the following into a textfile and save as per above
a) Map:
=============================
- 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 "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
tell application "Safari"
open location 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
b)Directions:
=================
-- 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 "Get Google directions to " & 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
set myAddress to first address of my card
showMapDirections(street of myAddress, zip of myAddress, city of myAddress, state of myAddress, country code of myAddress, 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 showMapDirections(mystreet, myzip, mycity, mystate, mycc, tostreet, tozip, tocity, tostate, tocc)
set addressURL to ""
if myzip is missing value then
set addressURL to stripReturn(mystreet) & ", " & mycity & ", " & mystate
else
set addressURL to stripReturn(mystreet) & ", " & myzip
end if
set addressURL to addressURL & " to "
if tozip is missing value then
set addressURL to addressURL & stripReturn(tostreet) & ", " & tocity & ", " & tostate
else
set addressURL to addressURL & stripReturn(tostreet) & ", " & tozip
end if
set addressURL to urlencode(addressURL)
try
--tell application "Firefox"
-- OpenURL googleMaps & addressURL
tell application "Safari"
open location googleMaps & addressURL
activate
end tell
on error error_message
display dialog error_message buttons {"OK"} default button 1
end try
end showMapDirections
-- 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