Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Latest commit

 

History

History
66 lines (54 loc) · 5.67 KB

hs.pasteboard.watcher.md

File metadata and controls

66 lines (54 loc) · 5.67 KB

docs » hs.pasteboard.watcher


Watch for Pasteboard Changes. macOS doesn't offer any API for getting Pasteboard notifications, so this extension uses polling to check for Pasteboard changes at a chosen interval (defaults to 0.25).

API Overview

  • Functions - API calls offered directly by the extension
  • interval
  • Constructors - API calls which return an object, typically one that offers API methods
  • new
  • Methods - API calls which can only be made on an object returned by a constructor
  • running
  • start
  • stop

API Documentation

Functions

Signature hs.pasteboard.watcher.interval([value]) -> number
Type Function
Description Gets or sets the polling interval (i.e. the frequency the pasteboard watcher checks the pasteboard).
Parameters
  • value - an optional number to set the polling interval to.
Returns
  • The polling interval as a number.
Notes
  • This only affects new watchers, not existing/running ones.
  • The default value is 0.25.

Constructors

Signature hs.pasteboard.watcher.new(callbackFn[, name]) -> pasteboardWatcher
Type Constructor
Description Creates and starts a new hs.pasteboard.watcher object for watching for Pasteboard changes.
Parameters
  • callbackFn - A function that will be called when the Pasteboard contents has changed. It should accept one parameter:
  • A string containing the pasteboard contents or nil if the contents is not a valid string.
  • name - An optional string containing the name of the pasteboard. Defaults to the system pasteboard.
Returns
  • An hs.pasteboard.watcher object
Notes
  • Internally this extension uses a single NSTimer to check for changes to the pasteboard count every half a second.
  • Example usage: lua generalPBWatcher = hs.pasteboard.watcher.new(function(v) print(string.format("General Pasteboard Contents: %s", v)) end) specialPBWatcher = hs.pasteboard.watcher.new(function(v) print(string.format("Special Pasteboard Contents: %s", v)) end, "special") hs.pasteboard.writeObjects("This is on the general pasteboard.") hs.pasteboard.writeObjects("This is on the special pasteboard.", "special")

Methods

Signature hs.pasteboard.watcher:running() -> boolean
Type Method
Description Returns a boolean indicating whether or not the Pasteboard Watcher is currently running.
Parameters
  • None
Returns
  • A boolean value indicating whether or not the timer is currently running.
Signature hs.pasteboard.watcher:start() -> timer
Type Method
Description Starts an hs.pasteboard.watcher object
Parameters
  • None
Returns
  • The hs.pasteboard.watcher object
Signature hs.pasteboard.watcher:stop() -> timer
Type Method
Description Stops an hs.pasteboard.watcher object
Parameters
  • None
Returns
  • The hs.pasteboard.watcher object