Sunday, June 24, 2007

Automatically update Adium buddy icon with iSight snapshot

So last monday I thought it would be fun to update my Adium buddy icon with how I currently look by taking a new image with the iSight camera that is built into my MacBook Pro. The reason was that I was wearing a suit with necktie and everything to work, something I don't usually do.

One of my IM buddies , Peter Krantz, saw this and commented in shock and awe claiming that was no way for a developer to dress. But he also had a really nice idea - that it would be cool to be able to get an updated image of your buddies every minute or so so you could see how they were looking today and if they where truly available or away.

I thought it was a nice idea and knowing that most OS X applications can be scripted through AppleScript I figured that it might be possible to implement this for Adium. I soon discovered that you can't take a iSight picture directly from AppleScript, but you can invoke a command called isightcapture that will accomplish this. After poking around in the AdiumXtras AppleScript section I also found some samples of how to change the buddy image. All that was remaining was a few hours of fighting with the weirdness that is AppleScript so I can present this little snippet to you:

    1 display dialog "Do you want to update your buddy picture?"
2 do shell script "/Applications/isightcapture " & POSIX path of file "Macintosh HD:private:tmp:buddyicon.jpg"
3 tell application "Adium"
4 set img to alias "Macintosh HD:private:tmp:buddyicon.jpg"
5 set fileid to open for access img -- opens the image
6 set tifimagedata to read fileid as TIFF picture -- reads the image
7 set default image to tifimagedata -- sets the buddy icon
8 close access fileid
9 end tell

What it actually does: Asks you if you want to update your picture, if you do it will take a snapshot with your iSight camera and set it as your default image in Adium (be sure to select the global buddy icon for all accounts for this to work).

What I haven't figured out yet is how to make this run everytime I start Adium. I have only managed to attach it to in-chat trigger words (like "/snapshot"). Or how to make this take a snapshot a timed interval. If you have any hints, then please leave a comment.

Update: Finally got it working!


Baloney Sammitch said...

This is fantastic. I love the Internet. I was sitting here idly eating a burrito at my iMac and though, "Hey, why not take a picture of this for my profile." Then I thought, why not do it every 5 min? It would be a simple apple script and I could also keep track of how I look for some kind of art project or youtube movie. Then I thought, I'm not that original, someone online has already done this.

Thank you kind sir. You've given me a lovely starting point. I'll get back to you if I make any improvements.

Johan Lind said...

Awesome! I'm happy that someone finds this useful/funny/interesting. :)

Twitter Updates

Johan Lind's shared items