Use Google Maps with the Address Book widget
In last Friday’s blog, we discussed how to safely use modified Dashboard widgets. When you place a copy in your user folder /Library/Widgets folder, OS X uses the copied widget instead of the original stock widget. This week, we’re going to use that trick to create a modified version of the Address Book widget.
The Address Book widget is quite useful. Not only can you browse and search your contacts, but with a click on the contact’s address, your default browser displays a MapQuest map (the screenshot to the left, below this paragraph) to that location. MapQuest is a fine service, but it lacks some of the cool features that “new kid on the block” Google Maps supports, such as pop-up balloons with location information and the ability to scroll through the map with the mouse. Wouldn’t it be nice if you could use Google’s mapping service (pictured on the right, below) with the Address Book widget? I mean, really, which map would you rather use?
Obviously, you can, or I wouldn’t be sharing this hint with you today! Although today’s tip is relatively long, it’s really not that hard—I’ve just tried to thoroughly explain each step in the process.
The first thing to do is to make a copy of Apple’s Address Book widget, per last week’s blog entry. Open two Finder windows. In the first window navigate to the top-level /Library/Widgets folder. In the second, navigate to your user folder /Library/Widgets folder (create a Widgets folder here, if necessary). Now just drag the Address Book widget from the top-level Widgets window into your user’s Widgets folder. OS X protected the top-level directory, so the system will automatically make a copy of the widget instead of moving it. You’ve now got a safe backup (the original widget file, in its original location) along with a copy that we’ll use for this hint.
Replacing the map server in the Address Book widget isn’t as trivial as changing a text string in a preferences file. That’s because Apple has compiled the code (which means it’s in binary form) that contains the MapQuest URL—and compiled code can’t simply be edited like a straight text file. Instead, you have to use a hex editor, and be very, very careful when making changes. If you make even one minor typo, then you’ll kill the program for sure. Thankfully, we don’t have to do any of that stuff, as a macosxhints.com reader has done the hard work already. Instead, we’ll just have to do a bit of work with Terminal (/Applications/Utilities) to create a script.
Creating the script
The easiest way to create the script on your own machine is to view the already-written source code in your browser. Then use the browser’s Save menu item (in Safari it’s File: Save As; in Firefox, it’s File: Save Page As) to save a copy locally. The file should be named abwidgetmap.sh; if OS X kindly points out that your text file is missing a .txt extension, do not add one:
As for where to save the file, it probably won’t matter, given that you may not use this program very often. Find a folder within your Documents folder, if you wish. If you have other scripts saved in another location, you could save this one there, too. If you’re a stickler for Unix folder structures, save it to your user’s
folder, or to
/usr/local/bin. In short, it doesn’t really matter; just remember where you put it.
So now you’ve got a bunch of complex-looking Unix code saved as a file on your Mac. So what’s this code do? This script toggles your copy of Address Book’s mapping service between MapQuest and Google Maps. Since the widget uses MapQuest by default, the first run will switch it to Google Maps. For most of you, that’s the only time you’ll need this script. But if you ever needed the MapQuest maps back—if, for instance, you’re um, oh, I don’t know, a Mac technology writer who needs a screenshot of the default Address Book mapping service—you can just run the script again, and you’ll have the MapQuest maps back.
So how does it work? Quite honestly, it’s a bit like magic to me, too, and a full breakdown of the script’s functionality is well beyond the scope of this hint, not to mention my education. But basically, the script creates a backup copy of some code within the widget, checks to see what the current widget is set to do, then uses a Unix program called
to insert the proper search URL (Google Maps or MapQuest) in a binary-encoded form into the file. Each time you run the script, the mapping service alternates between Goole Maps and MapQuest.
Using the script
Before you can use the script, you need to tell your Mac that this particular collection of text is an actual program, not just a text file. Open Terminal, and use
to navigate to the directory where you saved the file. For instance, if you saved it to a folder named Scripts in your user’s Documents directory, you’d type:
After you press Return, Terminal will move into that folder. Once there, use this command to make the code executable:
chmod a+x abwidgetmap.sh
Now you’re ready to use the script. To do so, just type:
at the front is needed because you’re running the script from the directory you’re currently in. You can run it from anywhere else you want, by just supplying the full path:
~/Documents/Scripts/abwidgetmap.sh. If you find yourself doing this a lot, and you have some Unix experience, just move the script to a folder that’s on your path.
The first time you run the script, you should see this output in the Terminal:
AddressBook Widget replaced - now using the Google map server
Run this script again to revert it back to MapQuest
Don’t forget in order for the change to take effect you must re-launch the AddressBook Widget in Dashboard.
Just refreshing the widget via Command-R won’t force the changes to take effect.
You can also have two copies of the Address Book running - one with MapQuest the other with Google.
To make the changes take effect, you have to close the Address Book widget first (in the Dashboard layer, hold down Option, hover over the widget, and click the close box). Just reloading it via Command-R won’t work. As noted above, this means you could actually have both mapping services available. Just open the Address Book widget prior to running the script, run the script, then open another copy of the widget from the Dashboard bar.
There you have it—Google Maps in the Address Book widget, easily reversible, and you haven’t even modified the standard widget at all!