HSSharingService
TypeA configured sharing service, wrapping NSSharingService.
Create instances via hs.sharing.createShare() or hs.sharing.servicesFor().
Configure with setCallback(), recipients, and subject as needed, then call
shareItems().
- Example:
hs.sharing.createShare(hs.sharing.builtinServices.mail)
.setCallback((event, items, error) => {
if (event === 'didShare') console.log('Shared!')
else if (event === 'didFail') console.error('Failed: ' + error)
})
.shareItems(['Check this out', 'https://www.hammerspoon.org'])
Properties
recipients
string[]
Recipients (e.g. email addresses) for services that support them, such as Mail or Messages.
permanentLink
string
A permanent link to the shared content, if the service provides one. Populated once
the share is in progress; otherwise null.
accountName
string
The account name used to perform the share, if applicable. Populated once the share
is in progress; otherwise null.
attachments
string[]
File paths of any attachments included in the share, populated once the share
completes. Empty until then.
Methods
setCallback(fn) -> HSSharingService
Registers a callback for share lifecycle events.
Declaration
setCallback(fn) -> HSSharingService
Parameters
| Name | Type | Description |
|---|---|---|
| fn | function | Called with the lifecycle event name, items, and optional error message |
Returns
HSSharingService
this share object, for chaining
Example
share.setCallback((event, items, error) => console.log(event))