ab2vcard is a Mac OS X tool that extracts all of the entries in the OS X Address Book to individual vCard files, optionally checking the results into Subversion.
Usage summary:
$ ab2vcard -h
usage: ab2vcard [-h] directory
-s commit into subversion
-d delete old files
-h displays help (this)
extracts all vCards from Address Book into directory
My primary use for this tool is to extract data from the OS X Address Book and export it into a Subversion version-control tree. This way, I have a record of how my Address Book entries have changed over time, as well as a permanent backup of my addresses. However, you don’t have to have Subversion installed to use this tool; it’ll work just fine without it.
To export everything from your Address Book into /tmp/vcards, just do this:
$ ab2vcard /tmp/vcards
The /tmp/vcards directory must already exist. This will produce one vCard file for each entry in your address book. You can re-run ab2vcard over and over again, and it’ll keep updating your files. By default, however, it won’t remove files when your delete people from your Address Book. To do that, use the ‘-d’ flag:
$ ab2vcard -d /tmp/vcards
WARNING: this will delete all files in the target directory that don’t match users in your Address Book. Running ‘ab2vcard ~’ would probably be a major mistake.
To use with Subversion, you need to already have a Subversion repository created, and then check that repository out on your Mac. My repository is called ‘svn’, and it lives on one of my home PCs. I’ve checked out the ‘svn’ repository into a directory tree called ‘svn’ in my Mac’s home directory, and I keep all of my addresses in a subdirectory of svn called ‘addresses’. That is, my addresses are in ~/svn/addresses/.
To keep that directory synced with my Address Book, all I need to do is run this:
$ ab2vcard -s -d ~/svn/addresses
This will automatically check new cards into Subversion, delete deleted cards from Subversion, and make whatever changes are needed when I make changes in the Address Book (or on my Palm, or on my Phone).
One caveat: you’re going to need to add the ‘addresses’ subdirectory to Subversion before you run ‘ab2vcard -s’ the first time. To do this, just run:
$ svn add ~/svn/addresses
Once this is done, just add a cron entry for ab2vcard, and your addresses will be committed to Subversion automatically.
At the moment, all of the vCard files produced by ab2vcard look like either:
Bob Smith.vcf
or:
Round Stuff Pizza.vcf
There are a couple small points to watch for. First, most non-alphanumeric characters are converted to URL- style %xx encoding. This includes apostrophes (‘) and slashes (/), but not spaces. This may change in a future version of ab2vcard. If you care, let me know.
The official home for ab2vcard is http://scottstuff.net/ab2vcard/. You may also want to watch my blog for details.
ab2vcard is derived from ‘contacts’ by Shane Celis. See http://gnufoo.org/contacts/. This is my first exposure to Objective C, so don’t expect completely idiomatic code. It seems to work, though.
Scott Laird scott@scottstuff.net