Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Get Google directions via Address Book Apps
I have created a new Google/Address Book script, based on the excellent AppleScripts from the Map Address Book addresses via Google Maps hint. This new script uses the first address in your "me" card to get directions to the selected address. I also added comments so that folks unfamiliar with AppleScript can figure out what's going on.

I've also gone and combined the best of both of those originally posted "map this" scripts into one new revised "Google Map of" script. I've created an installer for these scripts, and placed it (and the scripts) on my site. Thanks go to Unixjunkie and MikeD for their work!

[robg adds: I haven't tested the installer, but I did test the revised basic mapping script (works great). But the reason I ran this as a new hint is for the Google directions script. It worked perfectly using some test addresses in my Address Book. According to Google, I'm "one day and 15 hours" from my dad's house back east, assuming I don't actually want to stop to sleep :). I have placed both the revised Google mapping script and the new Google direction script on macosxhints, just in case they are no longer available at the above URL. I have not mirrored the installer.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[32,279 views]  

Get Google directions via Address Book | 21 comments | Create New Account
Click here to return to the 'Get Google directions via Address Book' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Get Google directions via Address Book
Authored by: SeattleSeth on Thu, Feb 17 2005 at 11:41AM PST
This script works great! However, I have multiple addresses under the 'me' card. I am not an expert scripter by any means, and was wondering how one could modify the script to pick one addreses vs. another? I have tried modifying which address to take by telling it to take the second or last address on my card (for my home address), but still takes the first address (work).

any suggestions would be greatly appreciated! thanks in advance!

-- 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

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: aamann on Thu, Feb 17 2005 at 12:04PM PST
Not tested but the following should work:

set myAddress to the first address whose label is "home" of my card

Of course, if you have more than one "home" address, this still might not work as expected - but then you probably should get your life together first :-)

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: SeattleSeth on Thu, Feb 17 2005 at 12:43PM PST
thanks for the suggestions.

I tried this directly and get an error stating that access is not allowed when I try to compile. When i remove quotes from home it compiles, but then does nothing when i try to use the script in address book.

any further assistance would be apprecaited, thanks!

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: aamann on Fri, Feb 18 2005 at 12:56PM PST
Sorry, I should have actually tried it first :-)

This one works:

set myAddress to (address 1 whose label is "home") of my card

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: noel_gomez on Thu, Feb 17 2005 at 2:44PM PST
Would it be possible to modify this script so it could be run from the script menu? I'd like to map an address from an email or a web page.

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: akakie@acsalaska on Thu, Feb 17 2005 at 3:50PM PST
I installed the two scripts into ~/Library/Address Book Plug-Ins and Address Book promptly stopped working. I removed the scripts to the desktop; same result. Moved them to the trash; ditto. I didn't empty the trash. I did log off and back on but not restart. "Stoppped working" means I get the spinning colors ball and have to force quit Address Book. Since I have to travel tomorrow, I kind of need the address book on this laptop (PB G4, OS 10.3.8).

HELP!

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: akakie@acsalaska on Thu, Feb 17 2005 at 4:02PM PST
Amendment: Address Book is back. I emptied the trash and restarted. Restart failed! (little clock like thingine goes round forever). I force the PB off and did a full startup (heart in mouth -- very crowded). The original "Google map of" script worked find.

If anyone has a suggestion about this scary incident, I would love to hear. Maybe I'll play with it AFTER my trip.

Thanks.

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: akakie@acsalaska on Thu, Feb 17 2005 at 4:27PM PST
Arrgh!

Be self reliant. Be persistent. Fix it your(my)self.

Deep in the URL code were a pair of single character symbols for "not equal" that didn't translate through tall the copy/paste stuff from web to editor.

Replacing them with "is not equal to" fixed the script.

<sigh>

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: Werd on Fri, Feb 18 2005 at 12:30AM PST
This script is great! I was hoping it wouldn't be long after the original "map of" script before someone figured out how to get directions directly (especially since Google Maps wants addresses on one line, which prevents simple copying and pasting into the "End address" field).

It is important to note, as akakie@acsalaska discovered in the above comments, that you can't open the text file in Safari or Firefox, and then copy and paste into Script Editor. Apparently browsers don't completely support the "less than or equal to" and "greater than or equal to" characters in text files. Is this a bug, or some kind of ASCII/Unicode limitation?

Strangely, option-clicking the links in Safari to download the text files from Mac OS X Hints gives me a "file doesn't exist" error, even though the files obviously do exist. (Doing the same thing on samer's site works fine, so I don't know what's going on there.) You can either "Save Linked File As..." from the contextual menu or once the text file is open in your browser, do a normal "Save As..." Even though the file doesn't appear (or copy) correctly in the browser, the saved file will be fine when opened in TextEdit or whatever.

[ Reply to This | # ]

Get Google directions via Address Book
Authored by: Werd on Fri, Feb 18 2005 at 2:34AM PST
One more thing I noticed...
Addresses get cut off on a "#" sign (as used for apartment numbers). Google Maps itself ignores apartment numbers and goes on to correctly map the addresses, but the AppleScripts choke on them.

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: Werd on Fri, Feb 18 2005 at 3:15AM PST
Ah, I see what's wrong. The number sign (#) in the URL needs to be converted to:
%23
I don't have a clue how that urlencode script works, so can someone that knows what they're doing add an exception for this?

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: aamann on Fri, Feb 18 2005 at 1:04PM PST
No need for an exception for # - the urlencode script already converts that to "%23"

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: Werd on Fri, Feb 18 2005 at 11:42PM PST
It doesn't replace it for me. I get the number sign in Firefox's URL field with a "did not match any locations" error (because there's no city or ZIP, since it's not seeing anything past the number sign), and if I replace it with %23 by hand, it works fine. All other characters seem to translate fine. Is anyone else having this problem?

[ Reply to This | # ]
Get Google directions via Address Book
Authored by: peeejay on Sun, Apr 3 2005 at 5:12PM PDT
I had the same problem, and, based on the original "Google Map Of" script, I modified it thus: Replace the line

if street of v is not missing value then set params to params & street of v & " "

with

if street of v is not missing value then
set shortstreet to street of v
if shortstreet contains "#" then
set poundcut to offset of "#" in shortstreet
set shortstreet to get text 1 thru (poundcut - 1) in shortstreet
end if
set params to params & shortstreet & " "
end if

This truncates the street at the # symbol. There may be a better syntax, but Applscript is quite picky about the offset function. Obviously google ignores the unit number, but it does get you to the front door of the building!

[ Reply to This | # ]
GoogleMaps now supports Safari, can the scripts?
Authored by: alphatech on Sun, Feb 27 2005 at 11:19AM PST
Google Maps now (apparently) supports Safari. :)

I tryed to edit the scripts by simply changing the:

tell application "Firefox"

to

tell application "Safari"

but got the Syntax Error "Expected end of line but found identifier." in the "OpenURL googleMaps & addressURL" line on the property googleMaps.

As is plainly seen I am not much of a scripter. If the script can be updated or if someone can explain how to fix this it will be greatly appreciated. Thank you!

[ Reply to This | # ]
GoogleMaps now supports Safari, can the scripts?
Authored by: Werd on Mon, Feb 28 2005 at 4:03AM PST
Apparently Safari uses "open location" instead of "OpenURL". There's an updated script on samer's site (link in original hint).

It also seems to fix the problems I was having with number sign encoding, or at least this time the copy-and-paste worked correctly. Just make sure that your urlencode routine matches the original at http://harvey.nu/applescript_url_encode_routine.html. Specifically, check that it uses two "not equal to" symbols, rather than "less than or equal to" and "greater than or equal to" characters (or anything else weird you may get by copy-and-paste). The latter never made sense to me, but I figured the script was mostly working for me and working fine for everyone else, so I didn't question it...

So, disregard the above "One more thing I noticed..." sub-thread.

[ Reply to This | # ]
Another version
Authored by: robg on Tue, Mar 8 2005 at 9:56AM PST
User "Anonymous" submitted another Google driving directions script; this one based on an earlier MapQuest driving directions hint. I've uploaded it to the server in case anyone wants to take a look at it:

google_driving_scpt.txt

I tested it and it works, but it's clearly not unique enough to run as a separate hint, so here it is.

-rob.

[ Reply to This | # ]
Another version
Authored by: arakune on Wed, Apr 6 2005 at 9:40AM PDT
For what its worth, samer's script does not work properly with Canadian addresses (the city variable isn't being passed), while this new anonymous script does.

[ Reply to This | # ]
Get Google directions via Address Book for ANY browser google supports
Authored by: rgould on Tue, May 3 2005 at 11:24AM PDT
if you want these scripts to use your system browser (or at least a browser that google maps supports) rather than having these scripts hard-coded to use safari or firefox, comment out the hard coded stuff and add the following right behind it (it also does some minor error checking for you):
		--		tell application "Firefox"
		--			OpenURL googleMaps & addressURL
		--tell application "Safari"
		--	open location googleMaps & addressURL
		--	activate
		--end tell
		
		if addressURL is not equal to "" then
			tell application "System Events"
				open location "http://maps.google.com/maps?q=" & addressURL
			end tell
		end if


[ Reply to This | # ]
UK Modification
Authored by: ukkarhu on Tue, May 3 2005 at 5:50PM PDT
These files work fine if you are in the USA, but in the UK, they don't do a good job. Fortunately, by only using UK postcodes, you can get a good approximation. To do this, modify the files using Script Editor, click compile, then save. Probably best to make a backup of these files before editing: For Google Map.scpt, modify the line a couple of lines below the line '--This is where the magic happens' from:

if zip is missing value then
		set addressURL to stripReturn(street) & ", " & city & ", " & state
	else
		set addressURL to stripReturn(street) & ", " & zip
	end if
to:

if zip is missing value then
		set addressURL to stripReturn(street) & ", " & city & ", " & state
	else
		set addressURL to zip
	end if
Now click 'compile' then 'save'. Change the same lines on the file 'Google Map directions.scpt'. Now if your address has a postcode, only this will be passed to Google map and this seems to work really well.

[ Reply to This | # ]
UK Modification
Authored by: ukkarhu on Tue, May 3 2005 at 6:01PM PDT
Oops - for the 'Google Map directions.scpt', the idea is the same and the lines are in the same location (just below the comment '--this is where the magic happens'), but there are now two parts - myzip and tozip. Change the line so it reads:

if myzip is missing value then
		set addressURL to stripReturn(mystreet) & ", " & mycity & ", " & mystate
	else
		set addressURL to 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 & tozip
	end if
i.e. delete the bits just after each 'else' statement so only the 'myzip' and 'tozip' parts are passed to the addressURL variable.

[ Reply to This | # ]