node-mdfind
Node module for searching OSX Spotlight, using the built-in mdfind
shell command.Installation
npm install mdfind
Example
var mdfind = require('mdfind')
var res = mdfind({query:'kind:contact', attributes: ['kMDItemDisplayName', 'kMDItemEmailAddresses'], limit: 2})
res.output.on('data', console.log)
res.output.on('end', function () {console.log('**done**')})
/*
{ kMDItemPath: '/Users/myuser/Library/Application Support/AddressBook/Sources/some_guid/Metadata/some_guid1:ABPerson.abcdp',
kMDItemDisplayName: 'Steve Jobs'
kMDItemEmailAddresses: [ 'sjobs@apple.com' ] }
{ kMDItemPath: '/Users/myuser/Library/Application Support/AddressBook/Sources/some_guid/Metadata/some_guid2:ABPerson.abcdp',
kMDItemDisplayName: 'Bill Gates',
kMDItemEmailAddresses: [ 'billg@microsoft.com' ] }
**done**
*/
Docs
mdfind
is a single function which accepts a single options
argument, which can include the following options. These are parallels of the arguments to the mdfind
command, so check run man mdfind
to see more details.query
: String
man mdfind
attributes
: String
kMDItemPath
is exported for every file and does not need to be manually specified.limit
: Integer
directories
: String
names
: String
interpret
: Boolean
query
string search
would produce the following query string: (* = search* cdw || kMDItemTextContent = search* cdw)
Note that the
live
option, while supported by the shell command, is not currently supported.The
mdfind
function returns object with two keys:output
this is a Stream that outputs objects. Each file found will be passed to thedata
handler as an object with keys for all specifiedattributes
.terminate
is a function which can be called to stop the search at any time.