Sunday 16 September 2012

iPhoto vs Directory Structure Sanity

"Exporting iPhoto libraries to my NAS with a sensible directory structure"

Yes, we use iPhoto

I like iPhoto. So does my wife. We share an iPhoto library on the same iMac between user accounts by way of a sparse disk image with the appropriate permissions ignorance for us both to manage a single library.

It works for us

It works well enough, as long as we remember that the iPhoto app must be closed when not in use so when a fast user switching event happens the newly logged in user can open the library. Of course we have forfeited Time Machine backups of the library as it now exists on a volume that may as well be on an externally connected device. But I have a solution for that...

... outside of the Apple microcosm

I recently moved to Android when I replaced my 3GS with an GS3. We also never opted in to the Apple media distribution option, we just rely on plain old DLNA for much of our viewing pleasure, including photographs. There's a ReadyNas NV+ chugging along serving up our files and content .. So here's how I get our important iPhoto albums into a sane structure ready to be served up :-

All the heavy lifting is done by Phoshare


Phoshare

This tool has a great command line interface for scripting your iPhoto library grand plans. I can't say enough about it, just start using it..

Convention

So we (my household) have an agreement that if we want photos to be featured and available within our media serving environment they need to be in a named album (or smart album).

Schedule an export to the NAS

Once a day I run bash script out of cron on the iMac that copies/updates iPhoto albums and smart albums to a directory on my NAS over an AFP share. This is an incremental backup of named albums with Phoshare comparing the iPhoto library to the already exported files and only copying/updating new or changed photos. I do not include dated events (created by iPhoto when you add photos) in this process, although I do have a separate shell script that backs up only the events seeing as the disk image we keep the library on is not included in normal Time Machine backups. The process described below is purely to give us access to our important photo albums in a logically named directory structure outside of the iPhoto and Apple environment.

The script

#! /bin/bash

# Set up some constants
MEDIA_SERVER="192.168.1.6"
MEDIA_SERVER_SHARE_URI="afp://;AUTH=No%20User%20Authent@$MEDIA_SERVER/media"
MEDIA_SHARE_MOUNT_POINT="/Volumes/media"

PHOTO_LIB_DISK_IMAGE="/Users/Shared/PhotoLibrary.sparseimage"
PHOTO_LIB_MOUNT_POINT="/Volumes/PhotoLibrary"

IPHOTO_LIBRARY="$PHOTO_LIB_MOUNT_POINT/iPhoto Library"
MEDIA_SHARE_DESTINATION="$MEDIA_SHARE_MOUNT_POINT/Pictures/iPhoto/"


# Mount/Attach the iPhoto Library sparse image if not already attached
if [ ! -d "$PHOTO_LIB_MOUNT_POINT" ]; then
 echo "Attaching $PHOTO_LIB_DISK_IMAGE"
 hdiutil attach $PHOTO_LIB_DISK_IMAGE >/dev/null
fi

# Mount the media share if not already mounted
if ! mount | grep "$MEDIA_SHARE_MOUNT_POINT" > /dev/null; then
 echo "Mounting share $MEDIA_SHARE_MOUNT_POINT"
 mkdir -p $MEDIA_SHARE_MOUNT_POINT
 mount_afp $MEDIA_SERVER_SHARE_URI $MEDIA_SHARE_MOUNT_POINT
fi

# Export iPhoto albums to media share
echo "Exporting iPhoto albums to $MEDIA_SHARE_DESTINATION"
/Applications/Phoshare.app/Contents/MacOS/Phoshare -a . -s . -kfud --gps --pictures -x "Last Import|Last 12 Months|Flagged" --iphoto "$IPHOTO_LIBRARY" --export "$MEDIA_SHARE_DESTINATION"

You can see the full list of Phoshare CLI options here - "Scripting Phoshare"

No comments: