According to Apple, Spotlight is supposed to be able to index EXIF data. Unfortunately, none of my JPEGs’ EXIF data has been indexed. Even worse, some of the Spotlight metadata fields are obviously bogus, showing obvious bugs in Spotlight’s implementation.

To test Spotlight’s EXIF abilities, I used a JPEG from my D60 that I had annotated with EXIF and IPTC data using iView Media Pro. Using the mdls command-line tool, I asked for details on one of my images, and saw something like this:

halloween-2004-173.JPG -------------
kMDItemAttributeChangeDate = 1970-01-02 17:40:06 -0800
kMDItemFSContentChangeDate = 2004-10-30 22:43:23 -0700
kMDItemFSCreationDate  = 2004-10-30 22:43:23 -0700
kMDItemFSCreatorCode   = 0
kMDItemFSFinderFlags   = 0
kMDItemFSInvisible     = 0
kMDItemFSLabel         = 0
kMDItemFSName          = "halloween-2004-173.JPG"
kMDItemFSNodeCount     = 0
kMDItemFSOwnerGroupID  = 20
kMDItemFSOwnerUserID   = 501
kMDItemFSSize          = 1712816
kMDItemFSTypeCode      = 0
kMDItemID              = 3341125
kMDItemLastUsedDate    = 2004-10-30 21:43:23 -0700
kMDItemUsedDates       = (2004-10-30 21:43:23 -0700)

Notice that all of the metadata provided is simply generic file data–none of this is image-specific. There is no EXIF data, and no indication that Spotlight knows that this is an image. Also, the kMDItemAttributeChangeDate is weird–it’s not impossible that I’d lost my clock and not noticed for two days, but it’s unlikely.

Worse, after making a minor change to the JPEG and then waiting for the re-indexer to run, the Attribute Change Date became completely bogus, changing nearly every time I ran mdls. Here are a few sample values:

kMDItemAttributeChangeDate = 1969-12-31 16:00:06 -0800
kMDItemAttributeChangeDate = 125748-10-16 05:23:09 -0800
kMDItemAttributeChangeDate = 1976-10-14 07:29:24 -0700

I particularly like the way that it jumps from 6 seconds after the Unix epoch to 123000 years into the future and then back into the 70’s again.

Even after telling iView Media Pro to re-write all of the EXIF and IPTC data in the file, mdls still doesn’t show any EXIF details. This is disappointing–I’d hoped to be able use Spotlight to locate images in my photo collection, possibly searching by date, time, focal length, lens, location, subject, and so on.

As I see it, one of two things can be happening here. Either this is a bug in 10.4.0 or Spotlight’s indexing system works in two passes–first indexing files’ existence, and then looping back around to index the data inside the file. It looks like mdimport is still running on something on my box, even though the Spotlight dropdown claims to be finished.

Update: I think it’s running in two passes. If I manually run mdimport on my JPEG, then a bunch of EXIF data shows up in mdls:

halloween-2004-173.JPG -------------
kMDItemAcquisitionMake     = "Canon"
kMDItemAcquisitionModel    = "Canon EOS D60"
kMDItemAperture            = 6
kMDItemAttributeChangeDate = 2005-04-29 18:49:35 -0700
kMDItemBitsPerSample       = 32
kMDItemCity                = "Woodinville"
kMDItemColorSpace          = "RGB"
kMDItemContentCreationDate = 1903-12-31 16:00:00 -0800
kMDItemContentModificationDate = 2004-10-30 22:43:23 -0700
kMDItemContentType         = "public.jpeg"
kMDItemContentTypeTree     = ("public.jpeg", "public.image", "public.data", "public.item", "public.content")
kMDItemCopyright           = "2004 Scott Laird"
kMDItemCountry             = "USA"
kMDItemDisplayName         = "halloween-2004-173.JPG"
kMDItemEXIFVersion         = "2.2"
kMDItemExposureMode        = 1
kMDItemExposureTimeSeconds = 0.005
kMDItemFlashOnOff          = 1
kMDItemFocalLength         = 23
kMDItemFSContentChangeDate = 2004-10-30 22:43:23 -0700
kMDItemFSCreationDate      = 2004-10-30 22:43:23 -0700
kMDItemFSCreatorCode       = 0
kMDItemFSFinderFlags       = 0
kMDItemFSInvisible         = 0
kMDItemFSLabel             = 0
kMDItemFSName              = "halloween-2004-173.JPG"
kMDItemFSNodeCount         = 0
kMDItemFSOwnerGroupID      = 20
kMDItemFSOwnerUserID       = 501
kMDItemFSSize              = 1712816
kMDItemFSTypeCode          = 0
kMDItemHasAlphaChannel     = 0
kMDItemID                  = 3341125
kMDItemISOSpeed            = 7.64386
kMDItemKind                = "JPEG Image"
kMDItemLastUsedDate        = 2004-10-30 22:43:23 -0700
kMDItemPixelHeight         = 3072
kMDItemPixelWidth          = 2048
kMDItemRedEyeOnOff         = 0
kMDItemResolutionHeightDPI = 180
kMDItemResolutionWidthDPI  = 180
kMDItemStateOrProvince     = "WA"
kMDItemUsedDates           = (2004-10-30 22:43:23 -0700)
kMDItemWhiteBalance        = 1

This still isn’t perfect, though–I’m not quite sure where kMDItemISOSpeed = 7.64386 came from–it’s really ISO 100. Similarly, mdls reports the Aperture as 6 when it should be f/8. On the other hand, the focal length and shutter speed are correct, although it’s sort of weird to see shutter speed expressed as decimal seconds.

Update 2: It’s definitely a two-pass thing. After leaving my laptop running overnight, all of my JPEGs now have a full set of metadata associated with them. The ISO numbers and apertures are still wrong, but the rest of the data’s all there. So, it looks like Spotlight tries really hard to get basic data into the DB, and then makes a second pass filling in more details as time permits. Good to know–I haven’t seen this documented anywhere.