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…
:: Dave Walker 21:32 (EST/EDT) [+] ::
:: [/tech/computers/os/osx/apple]
:: tags: apple
:: Comments (5)
Comments:
Title:
Date: 5/6/2005 08:57:07
Actually, it's more like locate, stat, file and imagemagik. Is there anyway to recieve live file creation/change notifications from spotlight?
Title:
Date: 5/6/2005 09:11:29
There has to be a way, otherwise the live Finder window updating wouldn't work. (see the Quicktime movie linked at the bottom of http://arstechnica.com/reviews/os/macosx-10.4.ars/18) I'll try to find some sample code.
Title:
Date: 5/6/2005 11:32:43
(Man... 4th attempt to satisfy this captcha thing...) From the mdfind man-page:-live Causes the mdfind command to provide live-updates to the num- ber of files matching the query.Not entirely useful on its own, because it doesn't give you a fresh set of results, but I could see writing a script that watches for new input from an mdfind -live invocation and re-runs the original mdfind for new results. It does work, though. I've done some semi-complex queries for MP3s, then dropped a new one satisfying the query on my desktop, and watched the count instantly update in my shell. Now, if only they connected Spotlight up with the arbitrary extended metadata in HFS...
Title:
Date: 5/6/2005 11:51:53
Sorry about the CAPTCHA thing... On the plus side, I now waste 0 hours per week dealing with comment/trackback spam, so... Anyway, I can't wait to delve into scripting against this Spotlight further.
Title:
Date: 5/7/2005 09:34:16
Adam, check this link: http://www.macgeekery.com/tips/all_about_launchd_items_and_how_to_make_one_yourself
DELETE A FORTUNE! Don't some of these fortunes just drive you nuts?! Wouldn't you like to see some of them deleted from the system? You can! Just mail to "fortune" with the fortune you hate most, and we MIGHT make sure it gets expunged.