hammerspoon2-docs
    Preparing search index...

    Class HSSharingService

    A 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().

    Index

    Constructors

    Properties

    accountName: string | null

    The account name used to perform the share, if applicable. Populated once the share is in progress; otherwise null.

    alternateImage: HSImage | null

    An alternate icon for the service, if one is provided, otherwise null.

    attachments: string[]

    File paths of any attachments included in the share, populated once the share completes. Empty until then.

    identifier: string

    A unique identifier for this share object (UUID string).

    image: HSImage

    The service's icon.

    messageBody: string | null

    The message body, populated once the share is in progress. Empty until then.

    permanentLink: string | null

    A permanent link to the shared content, if the service provides one. Populated once the share is in progress; otherwise null.

    recipients: string[]

    Recipients (e.g. email addresses) for services that support them, such as Mail or Messages.

    subject: string

    The subject line, for services that support one, such as Mail.

    title: string

    The user-visible title of the service, e.g. "Mail" or "AirDrop".

    Methods

    • Checks whether this service can share the given items. Items may be strings (treated as a web/mailto URL if they parse as one, a file path if they start with / or ~ and the file exists, otherwise plain text) or HSImage objects.

      Parameters

      • items: (string | HSImage)[]

        The items to check

      Returns boolean

      true if this service can share all of the given items

      Unsupported items will be ignored

    • Registers a callback for share lifecycle events.

      Parameters

      • fn: (event: string, items: any[], error?: string) => void

        Called with the lifecycle event name, items, and optional error message

      Returns HSSharingService

      this share object, for chaining

    • Attempts to share the given items with this service. If the service cannot handle the items, this logs a warning and returns false without doing anything further. Otherwise the share is started; it is asynchronous — use setCallback() to find out when it completes.

      Parameters

      • items: (string | HSImage)[]

        The items to share

      Returns boolean

      true if the share was started

      Unsupported items will be ignored