How can I programatically fill a flash drive with my latest photos from iPhoto? Suppose I want to fill up a flash drive with the most recent photos in my iPhoto Library.


I want to end up with an external drive that has all my photos in a single directory (no nested folders)
Those photos that have been modified, I want the modified version of the photo to end up on the drive.
Those photos that have not been modified, I want the original version of the photo to end up on the drive
I want to start with the newest photo and work backward in time, so when the drive fills up, the latest photos will be included on the external drive.
I fully expect that the external drive cannot hold all the pictures in my library. Any warning to this effect must be non-modally, and not prevent the script from proceeding to fill the drive with the newest photos in my library, then halt gracefully when the disk is full.
I want to do this programmatically (shell or AppleScript), without launching iPhoto.


Does anyone know how to go about doing this? I've written some shell scripts over the years, but none of them quite work the way I'd hoped.

I suspect the right answer will involve some copying and some "if" statements.
I have written a script to do this for you. It is available here. It works with system Ruby (1.8.6 in Lion) with no external dependencies. This is how you use it (also included in the README):


  This script looks for an iPhoto '11 album data file in

~/Pictures/iPhoto Library/AlbumData.xml

  
  This is the standard place for iPhoto to store the album data file, so
  it's very likely you have it here if you have iPhoto.
  
  Recommended use for the script is to copy it to wherever you wish to
  backup the files to, then invoke it on the command line:

$ruby iphoto.rb

  
  This will scan the album data file, sort the photos by date, newest
  first, then copy them to the desired destination until the drive is
  full. Alternatively, you can manually specify the path you wish to
  copy to as an argument parameter, in case you want to store the script
  somewhere else:

$ruby iphoto.rb /Volumes/Backup

  
  This script was written with exactly one user in mind; that is why it
  has no other options.
  
  
  
  
  I have tested this on exactly one iPhoto library: mine. It works for me, but YMMV.
  The number in front of the files is the "DateAsTimerInterval" value from the album data file. I don't know how to convert it to a "real" date, but sorting by it does sort chronologically, so it's good enough for the purposes of this script.