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


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..


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



# 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

# 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"

# Export iPhoto albums to media share
echo "Exporting iPhoto albums to $MEDIA_SHARE_DESTINATION"
/Applications/ -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"

Thursday, 6 September 2012

Sass, Compass & my Eclipse projects

I wanted to integrate Sass/Compass CSS generation into my Eclipse projects with automated compiling of my .scss files.

I'm not really a front end guy and loathe managing CSS, particularly in CSS notation. I looked at Compass a few years ago, liked it, then forgot about it. I obviously hit some tipping point recently and went back to revisit it. The idea of features like mixins and variables appeal to me as a Java dev.

So here's how I do integration into my Java WebObjects projects in Eclipse 3.7.2 on Mac OS X 10.8.1.

First up - installing compass:
sudo gem update --system
sudo gem install compass
Now for my eclipse project..
cd ~/MyWorkspace/MyEclipseProject
As a part of my stock WebObjects (Project WOnder) project directory structure I'll make use of the Resources and WebServerResources directories.

My Compass project will live here:

My Sass source files will live here:

And my compiled CSS files will be created/updated here:

So I create a Compass project inside my Eclipse project:
cd Resources/compasscompass init --sass-dir ../sass --css-dir ../../WebServerResources/css-sass
and back to my project root
cd ../..
This creates the following project, source and css files:




For automatic build integration I create a dedicated build xml file in my Eclipse project root build-compass.xml containing the following:

<project name="MyEclipseProject" default="compass.compile" basedir="Resources/compass">
<target name="compass.compile">
<exec executable="compass" dir=".">
<arg value="compile"/>
<eclipse.refreshLocal resource="../../WebServerResources/css-sass" depth="infinite"/>

Now to set up an Ant Builder in the project's properties dialog.
Properties -> Builders -> New (and choose Ant Builder)

In the Main tab I give it a name, in this case compass.compile, and set the Build File value to the file we just created:

In the Targets tab I set Auto Build to and in the Build Options tab I "Specify Resources" referencing my Sass source file directory.

I can now edit my Sass source files in Eclipse, on save they compile to CSS in my WebServerResources directory which has been refreshed to reflect any changes.

My console output show me the following on successful compilation:

Buildfile: /Users/me/MyWorkspace/MyEclipseProject/build-compass.xml

        [exec] [31m [0m [32midentical [0m ../../WebServerResources/css-sass/ie.css 
        [exec] [31m [0m [32midentical [0m ../../WebServerResources/css-s [31m [0m [31m [0m [31m [0mass/print.css 
        [exec] [31m [0m [32midentical [0m ../../WebServerResources/css-sass/screen.css 
Total time: 1 second

or something like this on build failure:

Buildfile: /Users/me/MyWorkspace/MyEclipseProject/build-compass.xml

        [exec] [31m [0m [31m [0m [31m [0m [31m [0m [32midentical [0m ../../WebServerResources/css-sass/ie.css 
        [exec] [31m [0m [32midentical [0m ../../WebServerResources/css-sass/print.css 
        [exec] [31m [0m [31m    error [0m screen.scss (Line 15: Undefined variable: "$defaudltSpacing".)
        [exec] [33moverwrite [0m ../../WebServerResources/css-sass/screen.css 
        [exec] Result: 1
Total time: 1 second

As always YMMV..