Rescuing Data with F-Script
I have an old iMac. It’s not in a good state.
I don’t care that much, it’s old slow, and not a lot of use. The only remaining thing of value is the large collection of photos I have on there. I have an external drive, so it’s easy to copy them over.
All the photos are stored in iPhoto 5, which (from googling around) appears to be the version before they moved all the metadata into a big binary blob. And looking in the
iPhoto Library folder revealed a file
AlbumData.xml which contained details of all 12,000+ photos. Result!
Apart from one slight problem. I’d never used iPhoto’s “albums.” Well, I’d made one or two (mostly by accident). But for the most part, I’d left the photos in the import “rolls”, just renaming (e.g.) “Roll 42” to “Trip to Wales”. Now the rolls are represented in
AlbumData.xml, but without the roll names. Just “Roll 1”, “Roll 2”, etc.
So like any good engineer, I’ll spend a huge amount of time to avoid having to re-enter 340 roll names, which I could have done in a couple of hours. This information is necessary for whatever system I’ll be pulling the photos into afterwards, dammit!
iPhoto obviously knows what the name of each roll is, or it wouldn’t be able to display them. They’re just stored in some different place (a binary blob, as it happens). Thankfully, I can still run iPhoto. So long as I avoid the middle of the screen, anyway. Now I forget exactly where I heard about it (Core Intuition, perhaps?) but I remembered that F-Script Anywhere allowed inspecting a running Cocoa program.
F-Script itself is a smalltalk based language, built on top of Objective-C and the Cocoa runtime. The tutorial includes a nice side-by-side comparison with Objective-C. It’s pretty simple for the most part. F-Script Anywhere is an add-on that allows you to inject the F-Script runtime into any running process. I tried it with iPhoto and immediately had a command line and browser with complete access to all of iPhoto. It helped having a minimal knowledge of Cocoa (I could find the app delegate!)
However, this wasn’t enough on its own. I didn’t know my way around all the classes inside iPhoto. To that end, I used class-dump to piece together the classes and their relations.
Eventually after a few hours1, I came up with this.
app := NSApplication sharedApplication appCtrl := app delegate albumMgr := appCtrl archiveDocument albumMgr "Each roll (album) has an imageRec whose name is what we need." rolls := albumMgr rollAlbums "Pull out the mapping from pseudo-album name to roll name." keys := rolls name values := rolls imageRec name rollNames := NSDictionary dictionaryWithObjects:values forKeys:keys "Write the result to a plist." rollNames writeToFile:'/tmp/roll_names.xml' atomically:YES
One very interesting feature of F-Script is the loop. Or lack thereof. Did you see the
rolls is an array, which doesn’t respond to the
names method. So F-Script has magic to say “send the names message to each element of the rolls array”. There’s more on this in the messaging patterns section of the language guide. But it feels rather nice.
The end result is that I do have all the data I need to move my photos into the next system. I can now safely dispose of the broken iMac, much to the relief of the room that’s been harboring it.
As an aside, this whole business of Albums vs Rolls very much feels like an example of technical debt in a system which was rushed. There was no obvious reason to have rolls and albums represented so differently. But instead, they were bolted on in a strange fashion.
1Actual time period is undefined.