« | Main | »

May 27, 2009

This is a Ruby script to use the profile images from your facebook account to fill in the images of the contacts in your address book without images -- hence your contacts' images on your iphone -- you know, in case you forget what your friends look like:
facebookcontacts
Example usage:
% ./facebookcontacts
After this you'll be prompted to sign in and then OK the app Contacts to access your profile (this is needed to get your friends). Then it will
  1. Access your facebook account to get a list of your friends
  2. Access your address book to find those contacts that are both in your address book without an image and a friend in your facebook account
  3. Using these friends, download the profile image and import it into your address book
Some prerequisites:
  • facebooker: Needed to access your facebook account; to install it:
    % sudo gem install facebooker
  • RMagick: Needed to resize and crop the profile image; to install it:
    % sudo gem install rmagick
  • sqlite3: Needed to access your address book; to install it:
    % sudo gem install sqlite3
Some final notes:

I couldn't find a library that abstracted away a Mac AddressBook, so I had to make a minimal one. It turns out, the AddressBook is stored as a sqlite3 database and the images are stored in a directory Images relative to this database. So the class AddressBook simply maps full names to lists of images that should be there. We need a list because you may have duplicate entries

That brings up point 2, which is, that I couldn't get at the email address of people, so I'm using full names -- hence if you have two entries in your address book with the same name, but different peolple, expect screwy results.

I also couldn't get at the profile image of the users, so I'm using facebooker to get the ids, creating a profile url, and then parsing out the profile image from this page. This image turns out to be a php file whose content is a jpeg.

Oh yeah, and obviously, you can only use it for macs. And apparently doesn't work for some non-public profiles :(, but for some it does?

Posted by jeff at May 27, 2009 12:13 AM