Query the macOS Spotlight metadata database.
hs.spotlight wraps NSMetadataQuery to let you search for files and other
metadata objects indexed by Spotlight. Queries use NSPredicate syntax with
kMDItem* attribute keys (see hs.spotlight.attribute for common shortcuts).
Quick start
// Find all PDFs in the home directory and log their paths constq = hs.spotlight.create() q.setQuery("kMDItemContentType == 'com.adobe.pdf'") .setScopes([hs.spotlight.scope.home]) .setCallback((event) => { if (event === 'didFinish') { console.log('Found ' + q.count + ' PDFs') q.results().forEach(item=> console.log(item.valueForAttribute(hs.spotlight.attribute.path)) ) q.stop() } }) .start()
Query the macOS Spotlight metadata database.
hs.spotlightwrapsNSMetadataQueryto let you search for files and other metadata objects indexed by Spotlight. Queries useNSPredicatesyntax withkMDItem*attribute keys (seehs.spotlight.attributefor common shortcuts).Quick start
One-shot search convenience
Grouping results by attribute
Monitoring for live changes