API Docs

An individual result returned by a Spotlight query.

Instances are returned by HSSpotlightQuery.results() and related methods. Do not instantiate HSSpotlightItem directly.

Metadata values are read via valueForAttribute() using standard kMDItem* keys. Call attributes() to discover which keys are populated on a particular item. Common attribute key shortcuts live in hs.spotlight.attribute.

Properties

identifier

string
A unique identifier for this result object (UUID string).

Methods

attributes() -> string[]

Returns the list of metadata attribute names present on this item. The list is typically not exhaustive — some attributes (such as `kMDItemPath`) may be readable via `valueForAttribute()` even when absent from this list.
attributes() -> string[]
string[]
An array of attribute name strings
const item = q.results()[0]
console.log('Attributes: ' + item.attributes().join(', '))

valueForAttribute(key) -> NSObject

Returns the value for a specific metadata attribute, or `null` if absent. The return type depends on the attribute: common types include strings, numbers, dates, and arrays of strings. `NSURL`-typed values are automatically converted to their string representation.
valueForAttribute(key) -> NSObject
Name Type Description
key string An attribute key such as `"kMDItemPath"` or `hs.spotlight.attribute.path`
NSObject
The attribute value, or null
const path = item.valueForAttribute(hs.spotlight.attribute.path)
const name = item.valueForAttribute('kMDItemDisplayName')
console.log(name + ' at ' + path)