Module for interacting with the macOS pasteboard (clipboard)
The macOS pasteboard is "rich" — a single clipboard operation can carry multiple representations
of the same content for different applications to consume. For example, text copied from a web
browser may carry plain text, HTML, and RTF representations simultaneously.
Basic Usage
// Read and write plain text consttext = hs.pasteboard.readString() hs.pasteboard.writeString("Hello from Hammerspoon!")
// Check what types are currently on the pasteboard constavailable = hs.pasteboard.types()
// Write multiple representations at once hs.pasteboard.writeObjects({ "public.utf8-plain-text":"Hello", "public.html":"<b>Hello</b>" })
macOS has no built-in notification API for transient or confidential clipboard content, so a
community convention has emerged (see nspasteboard.org) around four
org.nspasteboard.* UTI marker types. These markers carry no payload — their mere presence on
the pasteboard signals intent to other applications.
Standard marker UTIs
UTI
Meaning
org.nspasteboard.TransientType
Content is temporary; it will be removed or overwritten shortly. Clipboard historians should not record this change.
org.nspasteboard.ConcealedType
Content is sensitive (e.g. a password). Historians should obfuscate it if displayed and ideally encrypt it if stored.
org.nspasteboard.AutoGeneratedType
Content was placed by an application without any user Copy action. Historians should generally skip recording it.
org.nspasteboard.source
The bundle identifier of the application that placed the content. Use an empty string when the source is unknown.
Legacy proprietary markers
Several apps defined their own markers before the org.nspasteboard.* standard existed.
UTI
Application
de.petermaurer.TransientPasteboardType
TextExpander, Butler
com.typeit4me.clipping
TypeIt4Me
Pasteboard generator type
Typinator
com.agilebits.onepassword
1Password (confidential)
com.apple.is-remote-clipboard
macOS (remote content)
For scripts that write to the pasteboard
If your script temporarily commandeers the pasteboard (e.g. to trigger a paste), add
Module for interacting with the macOS pasteboard (clipboard) The macOS pasteboard is "rich" — a single clipboard operation can carry multiple representations of the same content for different applications to consume. For example, text copied from a web browser may carry plain text, HTML, and RTF representations simultaneously.
Basic Usage
Pasteboard Conventions (nspasteboard.org)
macOS has no built-in notification API for transient or confidential clipboard content, so a community convention has emerged (see nspasteboard.org) around four
org.nspasteboard.*UTI marker types. These markers carry no payload — their mere presence on the pasteboard signals intent to other applications.Standard marker UTIs
org.nspasteboard.TransientTypeorg.nspasteboard.ConcealedTypeorg.nspasteboard.AutoGeneratedTypeorg.nspasteboard.sourceLegacy proprietary markers
Several apps defined their own markers before the
org.nspasteboard.*standard existed.de.petermaurer.TransientPasteboardTypecom.typeit4me.clippingPasteboard generator typecom.agilebits.onepasswordcom.apple.is-remote-clipboardFor scripts that write to the pasteboard
If your script temporarily commandeers the pasteboard (e.g. to trigger a paste), add
For scripts that monitor the pasteboard
If you are building a clipboard history tool with
addWatcher, skip or obfuscate entries that