ANN: Some routines for Spotlight
soapdog at mac.com
Sun Aug 21 12:53:09 CDT 2005
Since I started using MacOS X Tiger, I became very fond of Spotlight
since it reminds me of BFS.
Spotlight has support for very advanced queries using nested boolean
logic and cool metadata filters but those features are not exposed in
the normal spotlight ui. To access those functions you need to code
your query using Objective-C or use command line tools.
By the use of shell() command we can harvest most of the spotlight
power by calling commandline tools, the spotlight command line tools
start with md (from metadata).
More can be learned from the Ars Technica Tiger review at: http://
So, I took some time to create some functions that we can use to
harvest those powers and they are below:
function mdfind pQuery
-- This one find matching files based on a given query.
return shell("mdfind" && pQuery)
function mdls pQuery
-- Returns a chunk with all Metadata info for a given file.
return shell("mdls" && pQuery)
function MetadataToArray pQuery
-- Takes the metadata chunk and turns it into an Array.
-- This is easier to access than the chunk.
-- There are some extra steps to erase extra spaces.
local tTempA, tReturnValA
put mdls(pQuery) into tTempA
split tTempA by cr and "="
repeat for each line tKey in the keys of tTempA
get offset(" ", tKey)
get char 1 to (it - 1) of tKey
put tTempA[tKey] into tReturnValA[it]
function mdimport pFile
-- forces reindexing on a given file, use it after you change its
-- we all know that the kernel hooks should make this useless but...
return shell("mdimport" && pFile)
Have fun friends
More information about the use-livecode