Sync Apple Address Book with Google Contacts

Address Book has a hidden feature in the Preferences menu where you can choose to synchronize with Google. However, it requires an iPhone/iPod attached to show the option. If you do not have such a device, you'll need to cheat. Here is how:

Step 1: Fake an Attached iPod

In your ~/Library/Preferences folder, create a file named com.apple.iPod.plist with the following content (keep a copy somewhere else if you already have the file in case you want to undo the change):

{ Devices = { red-herring = { 'Family ID' = 10001; }; }; }

Now open the Preferences menu of Address Book. See the option "Synchronize with Google" showing up? Click the box to enable it. It will ask your Google account and password. Type in to store the account/password pair in Keychain so you don't need to type them each time you sync.

Step 2: Trigger the Initial Synchronization

Now you need to trigger the synchronization to start for the first time. To do so, open a Terminal window and type:

/System/Library/PrivateFrameworks/GoogleContactSync.framework/Resources/gconsync  --sync gconclid

It will take a few moments for the initial synchronization to finish. Warning: backup your Address Book and Google Contacts before you sync in case of anything going weird! I will NOT be held responsible for any data loss or damages!

Step 3: Make the Sync Run Periodically

You can use iSync to manually trigger the synchronization. But why bother? There are a number of ways to run background jobs in Mac OS X. Here I will use launchd, the unified daemon/agent manager to run the synchronization periodically in the background.

First you'll need to create a job file in XML. Here is the template:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.google.contacts.sync.addressbook.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>/System/Library/PrivateFrameworks/GoogleContactSync.framework/Resources/gconsync</string>
        <string>--sync</string>
        <string>gconclid</string>
        <string>--syncmode</string>
        <string>fast</string>
    </array>
    <key>StartInterval</key>
    <integer>300</integer>
</dict>
</plist>

Change the value 300 in the line <interger>300</integer> to whatever number you want. It is the number of seconds between two synchronization. I would recommend 300 seconds (5 minutes) an appropriate value for most people.

Now save the file to your ~/Library/LaunchAgents folder with the name com.google.contacts.sync.addressbook.plist and open a Terminal window and type the following command:

launchctl load ~/Library/LaunchAgents/com.google.contacts.sync.addressbook.plist

This will load the job to launchd. From now on the synchronization will run periodically in the background.

A Script for the Lazy

The process above is a little bit tedious to type. I've written a script to automate the process. Simply download the script file and save it in your Home folder with the name gconsync.sh. Then open a Terminal window and type bash gconsync.sh. Follow the instructions and you'll be ready in a few moments.