Show full content
Apparently it’s a feature available in Mac OS for many years but I’ve just now learning about it.
All credit goes to Bozhidar Batsov @ https://metaredux.com/posts/2019/12/22/mdfind.html
So, if you have hundreds of gigabytes of photos taken on various cameras and lenses, you definitely found yourself looking to filter your archive by certain combination of those.
Yes, it can be done in various photo catalogue applicaions but I find all of them unbearably slow and not well suited to my console-centric view of the world.
Rejoice – mdls and mdfind utilities courtesy of Spotlight Mac OS feature come to the rescue!
mdls imagename.png | grep "Model” will show you two fields of particular interest: kMDItemAcquisitionModel and kMDItemLensModel.
First is your camera model eg “NIKON P7000” and second one is (surprise) lens model eg “50.0 mm f/1.4”. Unfortunately. to the extent of my knowledge, the brand of the lens is not visible in this metadata format so if you have plural lenses of same pameters but different makes – you’re out of luck.
To query using those key-values, run `mdfind “kMDItemAcquisitionModel = NIKON P7000”
This uses Spotlight’s pre-built index of files so the query runs in sub-100-millisecond range which is lightspeed compared to what you would be waiting in GUI based workflow.
Personally I find special joy in randomly discovering photos I took a long time ago and above approach lens itself nicely to piping the outcome into | shuf -n 1 | xargs -I{} /Applications/qView.app/Contents/MacOS/qView {} & and voila, you have yourself a “show me a photo of the day taken by my old Nikon” command that can be tweaked to your liking.
mdls has your run of the mill metadata keys like kMDItemContentCreationDate, some bizzare values like kMDItemAestheticScore and lots of stuff that could have been useful had the values been standartised across the industry which they are sadly not eg `kMDItemMeteringMode` that my phone does not appear to set.
Since Spotlight is basically an OS-wide search capability, different metadata must be available in other types of files. Maybe some other time I’ll find an interesting use for querying those…






