Seek and Ye Shall Find or: Why I Wrote an Adobe Photoshop Lightroom Spotlight Importer

What catalog is that file in?

That’s what I hear often from my wife Meg; a professional photographer. Meg uses Adobe Photoshop Lightroom for cataloging the pictures she takes for her business as well as the pictures she take of our family. An underlying frustration that I find with Lightroom is the fact that photos become lost inside different catalogs on your hard drive, and Lightroom lacks the ability to search across catalogs. Some photographers believe the answer is to have a few monolithic catalogs. While these catalogs may contain everything in one searchable database, the catalogs become slow and unwieldy in a few short gigs of data. My answer is to have many small catalogs and harness the great search capabilities within the Mac OS — Spotlight. One small problem, Spotlight doesn’t inherently know how to index a Lightroom .lrcat file. In order to overcome this shortcoming, I wrote my own Spotlight plugin; something called an importer (See the Spotlight Importer Programming Guide).

SQLite

Lightroom catalog files are actually SQLite databases and therefore extracting the necessary data was quite simple. I first used SQLite Manager in Firefox to examine the database. I came up with the following simple query to get at the filenames I would need to pass to Spotlight:

SELECT originalFilename FROM AgLibraryFile

The next step was to run this query from within Objective-C. After using the familiar OmniSQLite framework from the larger OmniGroup framework, I settled on a much smaller wrapper, FMDB.

Importer

It took several days before I wrapped my head around Spotlight and the necessary components of an importer. Probably the most difficult concept to understand was Uniform Type Identifiers (UTI). Adobe does not identify a UTI for their catalog files. I had to create my own in order for Spotlight to identify the files and know what importer to use in order to index Lightroom catalogs. I came up with com.adobe.lightroom.library. This UTI is in the Info.plist file of my importer under the Exported Type UTIs section.

Packaging

Take note that the package I created for installing the importer places the importer in ~/Library/Spotlight. I chose the user’s home directory because I can install it without the need for a password. I also run this command

/usr/bin/mdimport -r ~/Library/Spotlight/LightroomSpotlightImporter.mdimporter

after install. That causes Spotlight to index files already on disk. See here for more info.

Source Code

The codes speaks well for itself and that is why the source is open and hosted at Github. I also created a nice Github project page for the code. You can find the page here and the source code here.

Screenshot

Here is the importer in use:

screenshot

Download

Download the installer package

11 comments

  1. Helo, it’s seems to be a fantastic “plugin”, but i could not make it work.
    Can you teach me?
    I’ve downloade te file you wrote, installed it, an then… should i search for an image filename or a keyword inside a catalog at the spotlight?
    It’s not working…
    Thanks.

    1. Henrique,
        Try and search for a known filename that exists in one of your catalogs by clicking the magnifying glass at the far right of the menu bar on your Mac. Take a look at the screenshot above. You’ll see the Spotlight icon (the magnifying glass) is highlighted at the end. That is where you perform the search. Spotlight will then inform you as to which catalog(s) has a filename matching your search. If this doesn’t work, please let me know. Thanks!

        1. David, as you said at your main post…
          Was an index problem… everything is working now…

          GREAT JOB

          1. I could only find by the name of the file…
            Is that possible to find by a keyword?

          2. Henrique,
            I only coded file name however I will look into adding keyword for a future release. Thanks for the suggestion.

          3. Cool….

            let me know if you could add this feature… (contato@henriqueribas.com)
            Would be great.
            Thank you for your time… Great Job David…

          1. @337a23d52a84361a50424c1b73528cfd:disqus and @5b5e4b7e6f267a40384e67f86a0f2286:disqus, I have implemented the requested addition, however for whatever reason, Spotlight wasn’t behaving on my machine so nothing was working. Let me see if I can get things moving. Thanks!

  2. Great! I haven’t tried it yet, but this is precisely something that could be very usefull for me, and I will be giving it a shot as soon as I’m back to my studio.

    I can see why some people are interested in the keyword function, but definitely not a necessity for me.

    Thanks for this David!

Comments are closed.