#hs.sharing
Share items with the macOS Sharing Services under the control of Hammerspoon.
This module will allow you to share Hammerspoon items with registered Sharing Services. Some of the built-in sharing services include sharing through mail, Facebook, AirDrop, etc. Other applications can add additional services as well.
For most sharing services (this has not been tested with all), the user will be prompted with the standard sharing dialog showing what is to be shared and offered a chance to submit or cancel.
This example prepares an email with a screenshot:
mailer = hs.sharing.newShare("com.apple.share.Mail.compose") mailer:subject("Screenshot generated at " .. os.date()):recipients({ "user@address.com" }) mailer:shareItems({ [[ Add any notes that you wish to add describing the screenshot here and click the Send icon when you are ready to send this ]], hs.screen.mainScreen():snapshot() })
Common item data types that can be shared with Sharing Services include (but are not necessarily limited to):
- basic data types like strings and numbers
- hs.image objects
- hs.styledtext objects
- web sites and other URLs through the use of the hs.sharing.URL function
- local files through the use of file URLs created with the hs.sharing.fileURL function
#API Overview
Constants - Useful values which cannot be changed
Functions - API calls offered directly by the extension
Constructors - API calls which return an object, typically one that offers API methods
Methods - API calls which can only be made on an object returned by a constructor
- accountName
- alternateImage
- attachments
- callback
- canShareItems
- image
- messageBody
- permanentLink
- recipients
- serviceName
- shareItems
- subject
- title
#API Documentation
#Constants
Signature | hs.sharing.builtinSharingServices[] |
Type | Constant |
Description | A table containing the predefined sharing service labels defined by Apple. |
Notes | None |
Source | extensions/sharing/sharing.lua line 34 |
#Functions
Signature | hs.sharing.fileURL(path) -> table |
Type | Function |
Description | Returns a table representing a file URL for the path specified. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/sharing.lua line 41 |
Signature | hs.sharing.shareTypesFor(items) -> identifiersTable |
Type | Function |
Description | Returns a table containing the sharing service identifiers which can share the items specified. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 102 |
Signature | hs.sharing.URL(URL, [fileURL]) -> table |
Type | Function |
Description | Returns a table representing the URL specified. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 146 |
#Constructors
Signature | hs.sharing.newShare(type) -> sharingObject |
Type | Constructor |
Description | Creates a new sharing object of the type specified by the identifier provided. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/sharing/libsharing.m line 80 |
#Methods
Signature | hs.sharing:accountName() -> string | nil |
Type | Method |
Description | The account name used by the sharing service when posting on Twitter or Sina Weibo. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 361 |
Signature | hs.sharing:alternateImage() -> hs.image object | nil |
Type | Method |
Description | Returns an alternate image, if one exists, representing the sharing service provided by this sharing object. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/sharing/libsharing.m line 470 |
Signature | hs.sharing:attachments() -> table | nil |
Type | Method |
Description | If the sharing service provides an array of the attachments included when the data was posted, this method will return an array of file URL tables of the attachments. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 341 |
Signature | hs.sharing:callback(fn) -> sharingObject |
Type | Method |
Description | Set or clear the callback for the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 239 |
Signature | hs.sharing:canShareItems(items) -> boolean |
Type | Method |
Description | Returns a boolean specifying whether or not all of the items specified can be shared with the sharing service represented by the sharingObject. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/sharing/libsharing.m line 216 |
Signature | hs.sharing:image() -> hs.image object | nil |
Type | Method |
Description | Returns an image, if one exists, representing the sharing service provided by this sharing object. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/sharing/libsharing.m line 487 |
Signature | hs.sharing:messageBody() -> string | nil |
Type | Method |
Description | If the sharing service provides the message body that was posted when sharing has completed, this method will return the message body as a string. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 381 |
Signature | hs.sharing:permanentLink() -> URL table | nil |
Type | Method |
Description | If the sharing service provides a permanent link to the post when sharing has completed, this method will return the corresponding URL. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 450 |
Signature | hs.sharing:recipients([recipients]) -> current value | sharingObject |
Type | Method |
Description | Get or set the subject to be used when the sharing service performs its sharing method. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 272 |
Signature | hs.sharing:serviceName() -> string |
Type | Method |
Description | The service identifier for the sharing service represented by the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 421 |
Signature | hs.sharing:shareItems(items) -> sharingObject |
Type | Method |
Description | Shares the items specified with the sharing service represented by the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 185 |
Signature | hs.sharing:subject([subject]) -> current value | sharingObject |
Type | Method |
Description | Get or set the subject to be used when the sharing service performs its sharing method. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 315 |
Signature | hs.sharing:title() -> string |
Type | Method |
Description | The title for the sharing service represented by the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/sharing/libsharing.m line 401 |