Thu, 05 May 2005

Spotlight For Shell Scripters

Even if you happened to be a Unix geek who never touched the GUI, you could get some use out of Spotlight — if you’re shell scripting on Tiger, you’re in for a treat. Since the underlying indexing is tied in at the filesystem level, the indexes get updated whenever files are created on disk. Imagine rsyncing, say, a bunch of PNG files from another server somewhere. As soon as they are written through to your local HFS+ volume, their metadata is categorized on your OS X system, and immediately available to your scripts.

You can then use something like:

mdls dave-sp.png

which will return all of this.

dave-sp.png -------------
kMDItemAttributeChangeDate     = 2005-05-05 21:13:44 -0400
kMDItemBitsPerSample           = 32
kMDItemColorSpace              = "RGB"
kMDItemContentCreationDate     = 2005-05-05 21:13:44 -0400
kMDItemContentModificationDate = 2005-05-05 21:13:44 -0400
kMDItemContentType             = "public.png"
kMDItemContentTypeTree         = ("public.png", "public.image", "public.data", "public.item", "public.content")
kMDItemDisplayName             = "dave-sp.png"
kMDItemFSContentChangeDate     = 2005-05-05 21:13:44 -0400
kMDItemFSCreationDate          = 2005-05-05 21:13:44 -0400
kMDItemFSCreatorCode           = 0
kMDItemFSFinderFlags           = 0
kMDItemFSInvisible             = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "dave-sp.png"
kMDItemFSNodeCount             = 0
kMDItemFSOwnerGroupID          = 501
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 7550
kMDItemFSTypeCode              = 0
kMDItemHasAlphaChannel         = 0
kMDItemID                      = 4854899
kMDItemKind                    = "Portable Network Graphics Image"
kMDItemLastUsedDate            = 2005-05-05 21:13:44 -0400
kMDItemPixelHeight             = 128
kMDItemPixelWidth              = 128
kMDItemProfileName             = "Calibrated RGB Colorspace"
kMDItemUsedDates               = (2005-05-05 21:13:44 -0400)

It’s like ls and file and pnginfo all in one, and then some. I’m sure it doesn’t take a lot of imagination to figure out how to awk and sed and grep your way to glory with all of this.

Check out the manpages for mdfind, mdls, and mdimport, and have a ball...

:: 21:32
:: /tech/computers/os/osx/apple | [+]
::Comments (0)

Name:
E-mail:
URL:
Comment:
The Magic Word:
Which planet is closest to the sun? (hint -- it's Mercury...)




The most hopelessly stupid man is he who is not aware that he is wise.