Since a while I'm using iPhoto to manage my photo collection. One thing that kept annoying me was that I had to do manual actions to include selected photo's from iPhoto in my webalbum. Of course you can generate webalbums from iPhoto, but you need to do that over and over again each time you want to add more pictures to your webalbum. The solution I wanted to have was:

  • Import pictures into iPhoto
  • Tag them with keywords
  • Have them appear in my webalbum automatically
    • sorted by date
    • sorted to subject
I only need to maintain iPhoto and the rest is automatic.

I've got this working now for the sorted by date part. What I now do is:

  • In iPhoto I tag the pictures that I want to appear in my webalbum with a special keyword (webalbum)
  • Scheduled a cronjob that periodically:
    • Runs a ruby script sortImages.rb [note: this is an updated version of the previous script, the description in the blog post is not 100% accurate anymore] which parses the iPhoto AlbumData.xml file. This scripts selects all pictures with the 'webalbum' keyword and exports these to a directory structure in which they are sorted by year/month. (The script first checks if the AlbumData.xml is changed since the last run to prevent unnecessary work.)
    • If the ruby script sortImages.rb [see previous note] found any changes, kick of the webalbum application to update the webalbum (I'm using JAlbum, but you can use any webablum application that takes a directory structure as input).

The shell script is really simple.

ruby sortByDate.rb webalbum /tmp/webalbum '/path/to/AlbumData.xml'

if [ $? -eq 0 ]; then
cd /opt/JAlbum
java -Xmx256M -Djava.awt.headless=true -jar JAlbum.jar
-projectFile webalbum.jap -appendImages
fi
The sortImages.rb [see previous note] script takes 3 arguments:
  • The keyword that identifies the pictures to include in the webalbum.
  • The directory to which the pictures should be copied. In this directory new directories per year/month will be created.
  • The path to the iPhoto AlbumData.xml file

Writing the Ruby script was easy, it was the first time i really tried to do something with Ruby and I got it done pretty quick.... although I bet there is some improvement possible. Feel free to let me know ;-) The actual tricky parts were:

  • Figure out the structure of the AlbumData.xml file
  • Transform the DateAsTimerInterval element from the AlbumData.xml file into the date the picture was taken.

Next plan is to create a script that generates a directory structure using the other keywords set on the pictures. For example, group all pictures tagged with 'webalbum' and 'vacataion' and 'friends'. Sounds simple, but need to come up with some logic to be able to create a multi level structure where level one contains the images with only the 'vacation' keyword, level 2 has 'vacation' and 'friends' etc. What do I do with pictures that could end up in multiple parts of the tree?

*** Update ***

I just tested if this solution still works with iPhoto '09 and it works perfectly.

5 comments:

  1. Gero said...

    iPhoto '08 is released last month and for a couple of days I though that my scripts would not work with iPhoto '08. Fortunately they will, see http://forum.maccast.com/index.php?showtopic=13576
    Note: Comment imported. Original by Gero Vermaas ( email: gero@vermaas.net website: http://vermaas.net ) at 2007-09-13 15:27  

  2. Gero said...

    Hi, the link to the ruby script is broken.  Is there any way you could fix it?  I'm looking to do something similar for my web albums and your script seems like a really handy starting point.  Cheers.
    Note: Comment imported. Original by Brent ( email: gerodt.homeip.net@freakmaster.com website: null ) at 2008-01-12 15:41  

  3. Gero said...

    Yeah, the link is broken because I evolved the script to also sort by subject. The updated script is sortImages.rb. This one does a bit more, hope you can use it.
    Note: Comment imported. Original by Gero Vermaas ( email: gero@vermaas.net website: http://vermaas.net ) at 2008-01-14 20:17  

  4. Gero said...

    This is a wonderful idea, I've been looking for something like this for a while now. Can you post a tutorial for how one gets this going? I installed JAlbum but I don't know what I'd do next, I don't even know how I'd run your "simple" shell script.

    Instead of relying just on keywords, could the script be driven by a Smart Album? That seems a good idea.

    Thank you, I'm glad I found your page.
    Note: Comment imported. Original by wes ( email: wes@plate.net website: null ) at 2008-03-01 08:23  

  5. Gero said...

    For running shell scripts you can use the Terminal app (Applications/Utilities), but if you're not already familiar with that it may be easier to take a look at AppleScript. Also because it is not easily possible to use the Ruby script I created to access smart albums in the AlbumData.xml.  The AlbumData.xml only contains the definition of the SmartAlbum, but not the pictures that would be included in a smartalbum. This logic is inside iPhoto and using AppleScript you can access it and do similar things that I did in the ruby script. Another option might be to look at Automator, that is an more user friendly way, but I'm not sure if that provides all flexibility needed to access images and export them to specific folders (by year / keyword / etc).
    Note: Comment imported. Original by Gero Vermaas ( email: gero@vermaas.net website: http://vermaas.net ) at 2008-03-03 08:39  

Post a Comment