HSSpotlightItem
TypeAn 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
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[]
const item = q.results()[0]
console.log('Attributes: ' + item.attributes().join(', '))
valueForAttribute(key) -> any
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) -> any
| Name | Type | Description |
|---|---|---|
| key | string | An attribute key such as "kMDItemPath" or hs.spotlight.attribute.path |
const path = item.valueForAttribute(hs.spotlight.attribute.path)
const name = item.valueForAttribute('kMDItemDisplayName')
console.log(name + ' at ' + path)