Saturday, August 7, 2010

FileMaker- Quick OS X Address Book importing without plugins

In this article I will show you how to import your OS X Address Book contacts quickly without plugins.

When it comes to Address Book, developers usually choose two methods.
1) AppleScript looping- It's slow for many contacts.
2) Plugins- They are not free.

I'd like to share another method, which is basically 2-3 lines of code.

What you will need:

1, perform applescript command
2, one import command
3, sql knowledge

How?

Address Book stores its data in an sqlite database, which can be found at the $Home/Library/Application Support/Address Book folder.

OS X can access this using the built-in sqlite3 command. (Reference here).

With this sqlite3, we just simply execute an sql command to get the address book data exported to a tab separated file to a temporary path (Perform Applescript- Do shell script)
Then we'll just import is using the Import Records script step.
(See the attached demo file for working scripts)

SQL:
You have to build your own SQL commands to use this technique. There are many GUI SQLite browsers (even Firefox plugins!). Browse through the address book tables, and explore them. That's exactly what I did.
Also you can do a search on "OS X address book sqlite" to find sample sql scripts to experiment with.

I attached a sample file which has two sample scripts.
The first script imports just the first name, last name, middle name, company data.
The second one imports the contact's phone number, mobile and email address as well.



You can download a really simple demonstration from here . (right click- save as).
Feel free to modify the scripts, sql statements!


Note: I didn't spend much time to optimize the code. You should quit Address Book before exporting it's data. If you experiment with this technique, please do a backup of your address book db.

The attached sample may need to be modified if your address book database file is somewhere else.


- Adam


The material on this document is offered as is. There is no representation or warranty, expressed or implied, nor does any other contributor to this post. Consequential and incidental damages are expressly excluded. FileMaker Pro is the registered trademark of FileMaker Inc.