You may be familiar with the phrase “When all you have is a hammer, everything looks like a nail.” In other words, people tend to see solutions built with the tool they have available. In my case, my most available tool is FileMaker, and it came in very handy today.

We had an issue with some photos in iPhoto, where the little previews were working fine, but when you opened an image in full size, you only got a black screen with a question mark in the middle. I had no idea, but after a little searching, I found out the cause : it means that the thumbnail image is present, but the full size ( original and/or modified ) image is missing. Who knows why, and where they’ve gone, but the images for a whole section of our photos was gone. We wanted to print some books and we really needed those images.

I hunted through old backups to find them. They weren’t on our TimeMachine disk and the Crashplan offsite backup started after those went missing. But I did find an old copy of the disk that I’d mirrored using SuperDuper, so I was fortunate enough to have a copy I could restore from.

But the big issue was that iPhoto keeps all the images inside the iPhoto Library folder file, ( use show Package Contents to see inside ) and within that has folders for each year and subfolders for each album. So I would have had all sorts of issues trying to find out which images were missing. I wasn’t going to do this manually there are tens of thousands of images and hundreds of individual folders. I needed some sort of automation tool – gee what have I got lying around here – ah, FileMaker will do the trick.

“What you’re using a database to reconcile files on disk stored in iPhoto??? Are you crazy?” Yep, check that one.

My plan was to import the list of files ( original, thumbnail and modified ) from the iPhoto Library file, which is conveniently XML based, and then use my own BaseElements plugin to check for the existence of the files in the original location and on the backup disk. Then search for those that exist in the backup, but not the live, and copy across the ones that are missing.

I can see that anyone with any amount of Applescript, perl or shell scripting knowledge is already thinking something like “I could do that in 30 seconds with a 7 line perl script that no-one else can understand but will do the job perfectly”. I know there are lots of ways to get this job done, but in my case, my favourite hammer is FileMaker.

It turns out we had over 3500 missing images, so I was lucky I didn’t attempt to do this by hand. My FileMaker file worked perfectly, and using the BaseElements plugin to check for the files and copy those that are missing all worked without any problems.

I had to solve one issue in the XML because the way iPhoto stores the paths is a little odd ( in my opinion ). Instead of having a completely hierarchial structure, everything is stored within “dict” nodes, and to find out what each “dict” node is, you look at the previous node ( a “key” node ) and see what that node has. So it’s something like this :

<key>Master Image List</key>
<array>
<dict>
long list of things
</dict>
</array>

So your XML code needs to find the key that contains “Master Image List”, then go to the very next node and get a list of everything in the following “dict” node. The solution is relatively simple, you need to use a “following-sibling” to match the very next node. I’ve attached a copy of the xslt I used to this post for anyone interested.

Once I’d created the missing folders, copying all 3500 images took about a minute, and I was rather chuffed with how well it all worked out.

If you find you’ve got the same issue ( missing iPhoto images that show the question mark ), then you need to first find out if you’ve got a backup copy of the files somewhere. Only then can you do something like this where you selectively copy the files back to their original location. If the files really were gone, then no amount of FileMaker magic can bring them back. Make sure you’ve got good backups 🙂