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):
Signature | hs.sharing.builtinSharingServices[] |
---|---|
Type | Constant |
Description | A table containing the predefined sharing service labels defined by Apple. |
Source | extensions/sharing/init.lua |
Signature | hs.sharing.fileURL(path) -> table |
---|---|
Type | Function |
Description | Returns a table representing a file URL for the path specified. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/sharing/init.lua |
Signature | hs.sharing.URL(URL, [fileURL]) -> table |
---|---|
Type | Function |
Description | Returns a table representing the URL specified. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
Signature | hs.sharing:callback(fn) -> sharingObject |
---|---|
Type | Method |
Description | Set or clear the callback for the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
Signature | hs.sharing:serviceName() -> string |
---|---|
Type | Method |
Description | The service identifier for the sharing service represented by the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/sharing/internal.m |
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 |
|
Source | extensions/sharing/internal.m |
Signature | hs.sharing:title() -> string |
---|---|
Type | Method |
Description | The title for the sharing service represented by the sharingObject. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/sharing/internal.m |