Address Books on two Macs

It’s been a while since my last post, a period in which I’ve started and stopped a few posts that required lengthy exposition and clear organization to make them readable and useful. I hope to get at least one of them in shape and online soon, but until then, here’s a simple description of how I keep my Address Book in sync on two Macintoshes.

My main computer is an Intel iMac at my office; my secondary computer is an iBook G4. Because I don’t have a .Mac account (seems too expensive for what it provides), I need another way to keep my calendar and address book consistent between the two computers. For the calendar, I use the freely-available iCal Exchange service with iCal’s built-in publish and subscribe mechanism—a simple and obvious system that probably doesn’t need any more explanation. But there’s no publish and subscribe in the Address Book application like there is in iCal, so a different approach is needed.

My first step is to declare the Address Book on my office computer as the master version and the one on my iBook as the slave. I don’t enter any contacts on my iBook; it only knows what it learns from the master. When I’m on the road, meeting new people, I collect their business cards and wait until I’m back in the office to enter them into the iMac’s Address Book.

Getting my iBook Address Book to have the same contacts as my iMac Address Book consists of copying everything from the ~/Library/Application Support/AddressBook folder on the iMac to that same folder on the iBook. (Note: the “~” in the last sentence is a Unixism that refers to my home folder.) Any decent FTP or SFTP client can do that. I use Yummy FTP because I got it at a good discount during some promotion a couple of years ago, but Interarchy or Transmit or CyberDuck would work, too.

My office computer is accessible only by SSH, via port forwarding from the office router, so I use SFTP for the transfer. I have a Yummy FTP bookmark, cleverly called “Work,” to make the connection. Then it’s simply a matter of navigating to the correct folder and dragging from one pane to the other.

This manual method served me well, but since Yummy FTP is scriptable, the transfer can be turning into one-step operation. Here’s the AppleScript that does it:

 1:  if application "Address Book" is running then
 2:    quit application "Address Book"
 3:  end if
 4:  
 5:  tell application "Yummy FTP"
 6:    activate
 7:    connect "Work"
 8:    using connection "Work" list local folder "/Users/drang/Library/Application Support"
 9:    using connection "Work" list remote folder "/Users/drang/Library/Application Support"
10:    using connection "Work" set mode "Replace"
11:    with timeout of 30 * 60 seconds
12:      using connection "Work" download "AddressBook"
13:    end timeout
14:    disconnect "Work"
15:    quit
16:  end tell

I keep it in the iBook’s ~/Library/Scripts folder, where I can easily launch it using FastScripts Lite. It starts by quitting Address Book if it’s running, because I don’t think it’s a good idea to replace its data on the fly. The “if application x is running” construct on line 1 is new to AppleScript 2.0, so I don’t think it will work on pre-Leopard systems. The rest of the script is fairly straightforward. Yummy FTP’s AppleScript commands are kind of verbose, because they require the “using connection” prefix at the beginning of most of the important lines.

The only lines that may be a bit tricky are lines 10 and 11. Line ten sets the download mode to “Replace” because I always want to replace the files on the iBook with what’s on the iMac. Without that line, Yummy FTP will stop and ask me if I want to replace the local files—normally a good thing but not necessary here. Line 11 extends the usual AppleScript timeout value to 30 minutes. Without that line, an AppleScript timeout error message would pop up before the download finishes.

I’m sure similar scripts could be written for the other transfer programs.

Tags: