{"id":245,"date":"2005-04-30T12:55:16","date_gmt":"2005-04-30T11:55:16","guid":{"rendered":"http:\/\/wp.devco.net\/?p=245"},"modified":"2009-10-09T17:03:08","modified_gmt":"2009-10-09T16:03:08","slug":"spotlight_on_the_commandline","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2005\/04\/30\/spotlight_on_the_commandline.php","title":{"rendered":"Spotlight on the commandline"},"content":{"rendered":"

As pointed out in the excellent arstechnica review<\/a> Apple chose not to expose a fraction of the usefulness of Spotlight to the GUI, I suspect within days there will be a Shareware Spotlight power users GUI out that bridge this gap, I can only wish.
\nFor now, if you want to do some kick arse queries you need to use the command line and it really is very powerful. I scp’d a couple of my photos onto the apple hard drive and now I can do really nice queries over my photos like this one:<\/p>\n

\n
\n[rip@temptation]% mdfind 'kMDItemAcquisitionMake == \"nikon*\"c && \\\nkMDItemExposureTimeSeconds >= 1'\n\/Users\/rip\/Pictures\/book\/hms-belfast.jpg\n\/Users\/rip\/Pictures\/book\/london-eye.jpg\n\/Users\/rip\/Pictures\/book\/albert-bridge.jpg\n<\/pre>\n<\/blockquote>\n

The above bit will find all the photos on my drive shot by a Nikon camera with a exposure time of more than 1 second.
\nThis is pretty kewl, and a wealth of meta data gets stored by default for images, this is a dump of one of the above photos:<\/p>\n

\n
\n[rip@temptation]% mdls \/Users\/rip\/Pictures\/book\/albert-bridge.jpg\n\/Users\/rip\/Pictures\/book\/albert-bridge.jpg -------------\nkMDItemAcquisitionMake         = \"NIKON CORPORATION\"\nkMDItemAcquisitionModel        = \"NIKON D70\"\nkMDItemAperture                = 8.33985\nkMDItemAttributeChangeDate     = 2005-04-30 00:54:33 +0100\nkMDItemBitsPerSample           = 32\nkMDItemColorSpace              = \"RGB\"\nkMDItemContentCreationDate     = 2005-04-24 00:40:51 +0100\nkMDItemContentModificationDate = 2005-04-24 00:40:51 +0100\nkMDItemContentType             = \"public.jpeg\"\nkMDItemContentTypeTree         = (\"public.jpeg\", \"public.image\", \\\n\"public.data\",\"public.item\", \"public.content\")\nkMDItemDisplayName             = \"albert-bridge.jpg\"\nkMDItemExposureTimeSeconds     = 5\nkMDItemFlashOnOff              = 0\nkMDItemFocalLength             = 18\nkMDItemFSContentChangeDate     = 2005-04-24 00:40:51 +0100\nkMDItemFSCreationDate          = 2005-04-24 00:40:51 +0100\nkMDItemFSCreatorCode           = 0\nkMDItemFSFinderFlags           = 0\nkMDItemFSInvisible             = 0\nkMDItemFSLabel                 = 0\nkMDItemFSName                  = \"albert-bridge.jpg\"\nkMDItemFSNodeCount             = 0\nkMDItemFSOwnerGroupID          = 501\nkMDItemFSOwnerUserID           = 501\nkMDItemFSSize                  = 1072065\nkMDItemFSTypeCode              = 0\nkMDItemHasAlphaChannel         = 0\nkMDItemID                      = 455102\nkMDItemISOSpeed                = -2.321928\nkMDItemKind                    = \"JPEG Image\"\nkMDItemLastUsedDate            = 2005-04-24 00:40:51 +0100\nkMDItemOrientation             = 0\nkMDItemPixelHeight             = 1555\nkMDItemPixelWidth              = 2481\nkMDItemProfileName             = \"sRGB IEC61966-2.1\"\nkMDItemRedEyeOnOff             = 0\nkMDItemResolutionHeightDPI     = 300\nkMDItemResolutionWidthDPI      = 300\nkMDItemUsedDates               = (2005-04-24 00:40:51 +0100)\n<\/pre>\n<\/blockquote>\n

All isn’t perfect though, notice the kMDItemISOSpeed<\/i>? It’s blatantly wrong, so thats really a pain.
\nHere is a nifty little show off trick with mdfind, the GUI has the nice auto updating of results going which is obviously difficult to show in the command line world, but it has something at least.
\nTo set this up do a query that will match files – one that you can easily add more matches to.<\/p>\n

\n
\n[rip@temptation]% mdfind -live apple\n<snip>\nUsers\/rip\/Library\/Preferences\/com.apple.recentitems.plist\n\/Users\/rip\/Library\/Preferences\/com.apple.dashboard.plist\n\/Users\/rip\/Library\/Preferences\/com.apple.Syndication.plist\n\/Users\/rip\/Library\/Preferences\/com.apple.Safari.plist\n[Type ctrl-C to exit]\n<\/blockquote>\nNow here comes the magic, create some files that match in another term or through finder.\n
\n[rip@temptation]% mkdir apple\n[rip@temptation]% rmdir apple\n<\/pre>\n<\/blockquote>\n

If you paid attention to the other window you will see it updated on the fly like this:<\/p>\n

\n
\nQuery update: 378 matches\nQuery update: 377 matches\n<\/pre>\n<\/blockquote>\n

And to see just how deep the indexing goes, if you have Photoshop on your machine, create a new file and put some text on a image, something that will match your query. You will see Spotlight finds even this text on an image.<\/p>\n","protected":false},"excerpt":{"rendered":"

As pointed out in the excellent arstechnica review Apple chose not to expose a fraction of the usefulness of Spotlight to the GUI, I suspect within days there will be a Shareware Spotlight power users GUI out that bridge this gap, I can only wish. For now, if you want to do some kick arse […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[1],"tags":[23],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/245"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":1,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":680,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/245\/revisions\/680"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}