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.
Declaration
attributes() -> string[]
Returns
string[]
An array of attribute name strings
Example
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.
Declaration
valueForAttribute(key) -> NSObject
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | An attribute key such as `"kMDItemPath"` or `hs.spotlight.attribute.path` |
Returns
NSObject
The attribute value, or null
Example
const path = item.valueForAttribute(hs.spotlight.attribute.path)
const name = item.valueForAttribute('kMDItemDisplayName')
console.log(name + ' at ' + path)