Address Book vCard Publishing with AppleScript and SCP

The one piece of my .Mac replacement I’ve been missing is a way to publish our address book to the web. Every different web mail app has its own address book, and none of them sync with each other, with Outlook or, for me, Address Book.app — rendering all of them useless. So I needed my own way to, in a pinch, get addresses online. vCard PHP provides the parser and renderer, but I, obviously, needed to provide the group vCard for it to show me. Enter AppleScript again.
The goal of this script was to invoke Address Book.app’s Export command on all of the contacts in its database. I found a script online that exported individual vCards, so with a little modification I was able to get it to dump out a single group vCard. The next challenge was getting it up to my webserver.
I’m learning UNIX as well as AppleScript, so I was quite happy to put SCP to work. However, I hit a brick wall when trying to get AppleScript to pass in my server password. It can’t do it. I searched all over the Internets, but apparently once AppleScript invokes SCP, it loses control. And SCP obviously doesn’t have an AppleScript dictionary of commands. This behaviour is quite different from SSH, with which you do not lose control.
This sucked for a long time, until I finally broke down and decided to learn about RSA key pairs for authentication. I’ve been avoiding this for quite awhile now, because I frankly like just using a password, and I was scared of learning such an obscure new topic. But I finally figured it out — although that’s a topic for another post…
Anyway, assuming you have key pairs set up with your server, this script will do the trick. As I mentioned, it exports your Address Book to a group vCard in a given folder on your local hard machine, then SCPs the file up to a given folder on your web server. Point vCard PHP to that file, and schedule the AppleScript to run at a specific time using iCal, and you have an updated Address Book online!
Download the Script Here