25 Aug 2006

slow-drip photographic goodness

If you keep an eye on my flickr page, you'll know that I tend to add a whole bunch of pictures all at once. I don't really like doing that, because it means that you get overwhelmed with tons of pictures at irregular intervals and don't have the time to fully appreciate the splendour and beauty of each one. (Q: is dave full of himself?)

Anyways, I thought it would be nice to set up a queue of pictures and write a program to upload them once a day. At first I thought I'd write a huge program that would store pictures in a queue and let me give them tags and names and descriptions, and then I'd write all the code that talks to flickr, and so on. However, all those things have been written by other people, so my motivation to write them from scratch was approximately nil.

Then I realized that the only thing I really wanted was the queue. If I could somehow get the computer to pull one picture from a queue each morning and put it in my way, then I could just upload it myself. This, it turns out is much easier...

I added two albums to iPhoto: "flickr queue" and "flickr". Then I wrote a script that grabs the first image from the "flickr queue" albums, copies it to the desktop, does some processing to prep it for flickr and then moves the image from the "flickr queue" album to "flickr". Then I told launchd to run the script every morning and I'm all set. Everyday there will be one picture sitting on my desktop screaming to be uploaded!

Here's the script, if you're interested:

tell application "iPhoto"
set queue to the album named "flickr queue"
-- (count photos in queue) is equal to 1
if (count photos in queue) is greater than 0 then
set photo_of_the_day to the first photo in queue
set path_of_the_day to the image path of photo_of_the_day as POSIX file as alias
tell application "Finder" to set fresh_copy to duplicate path_of_the_day to the desktop
end if

add photo_of_the_day to the album named "flickr"
remove photo_of_the_day from the album named "flickr queue"

tell application "Image Events"
set image_of_the_day to open (fresh_copy as string)
scale image_of_the_day to size 1200
match image_of_the_day to destination profile "sRGB Profile"
save image_of_the_day
end tell

end tell