Saturday, February 4, 2012

Searching EXIF data with Mac OS X Spotlight

Using Mac OS X Spotlight, you can quickly search for certain camera metadata. A simple search would be "D300" (without quotation marks) entered in the field you get when you click on the magnifying glass in the upper right corner of your screen. That returns all images, both NEF and JPEG, that were taken with a Nikon D300 camera. By default you also get all other files that contain D300, like PDF files, word documents and old mails where you discussed the camera with friends. To limit the search to just images, go to "Show all in Finder". That will open a window with the title "Searching this Mac". Here you can click on a plus ⊕ symbol to get more search criteria. Click on it and select "Kind" as "Image", and you will only get image files.


If you instead of selecting Kind, select "Other", you get a vast number of search criteria to choose from, like ISO or EXIF version.

To really see all the criteria you can search from, you can use a Terminal window.
  1. Open the Terminal from Applications > Utilities > Terminal.
  2. Type "mdls " without quotation marks, but with the space after the last "s".
  3. Go to the Finder and drag an image file onto the Terminal window. It should now contain text that looks something like "$ mdls /Users/myhome/Desktop/mypic.jpg"
  4. Type "| less" after the file name and hit Enter.
What you now get is a list of searchable fields for the image, and their values:

kMDItemAcquisitionMake         = "NIKON CORPORATION"
kMDItemAcquisitionModel        = "NIKON D300"
kMDItemAlternateNames          = (
    "mypic.jpg"
)
kMDItemBitsPerSample           = 32
kMDItemColorSpace              = "RGB"
kMDItemExposureTimeSeconds     = 0.004
...

To move down to see more options, hit the Space Bar.
To move back up, type "B".
To leave the list, type "Q".

Now we can go back to Spotlight to use this information for an actual search.
  1. Click on plus ⊕ again, and select "Other".
  2. Select "Raw Query".
  3. In the search field, type a field name from the Terminal and some appropriate value, like "kMDItemExposureTimeSeconds < 0.003"
This will display all photos with a kMDItemExposureTimeSeconds (shutter speed) that is faster than 0.003 seconds.


If you know you want to repeat the same query over and over, you can hit the "Save" button, and you will get a virtual folder for quick access, whenever you need it.

Everything that is written here actually applies to all kinds of files, not only images, but as this is a photo blog, all the examples come from the wonderful world of images.

2 comments:

Tim said...

Thank you very much! I was trying to find all of the images take with a certain lens and now I am able to search by mm. Awesome post.

Al said...

That saved my ass!!!! AWESOME! Was able to restore about 1500 images so fast!!!!