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
alternateImage
An alternate icon for the service, if one is provided, otherwise null.
recipients
Recipients (e.g. email addresses) for services that support them, such as Mail or Messages.
permanentLink
A permanent link to the shared content, if the service provides one. Populated once the share is in progress; otherwise null.
accountName
The account name used to perform the share, if applicable. Populated once the share is in progress; otherwise null.
attachments
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.
The callback is called with:
event(string): one of"willShare","didShare","didFail"items(array): the items involvederror(string,"didFail"only): a description of the failure
setCallback(fn) -> HSSharingService
| Name | Type | Description |
|---|---|---|
| fn | (event: string, items: any[], error?: string) => void | Called with the lifecycle event name, items, and optional error message |
share.setCallback((event, items, error) => console.log(event))