Browse the docs

Clipboard

Sets, reads or clears the clipboard, and reads its history and named clipboards.

Set the clipboard

Keyboard Maestro: SetClipboardToText, SetClipboardToPastClipboard, DeletePastClipboard

Details #

Works with the system clipboard, mostly as plain text. Choose the operation with op. (action is another spelling of op.)

  • set puts value on the clipboard. The value can use variables. (text is another spelling of value.)

  • get reads the clipboard's text. The text is the step's output, and goes into the variable named in into, if you give one. If the clipboard holds no text, the result is empty and the Trace says so.

  • clear empties the clipboard.

  • history reads item index of the clipboard history (0, the default, is the newest) into the output and into. With set on it also puts that copy back on the clipboard. It fails when the history is empty or has no item there.

  • deleteHistory removes item index, or everything with all on.

  • setNamed keeps the clipboard (or text / value, if given) under name. getNamed puts the clipboard named name back and reads it into into. readNamed reads one without touching the system clipboard.

  • copyNamed, cutNamed and pasteNamed press ⌘C, ⌘X or ⌘V against a named clipboard and then restore the system clipboard.

  • choose lets you pick a past clipboard. In the Switchboard app it opens the clipboard panel (search, filters, previews); from the command line it shows a plain list instead. filter starts the panel on one kind of copy. What happens to the pick depends on then: set (the default) puts it on the clipboard, paste pastes it, none only returns it. Pressing ⎋ cancels the step.

  • transform runs another macro's clipboard action on text and gives its result back, so one macro reuses another's transform. macro is the id or name of a macro whose first input is a thing type (thing:text, thing:url, ...); text is what to transform (the clipboard's text when left out). The result is the step's output and goes into into. When a copy started the run (a Clipboard change trigger), the result also replaces the clipboard and clipboard history keeps the first-copied content on the row as its original; replace switches that on or off. A transform can't run itself. See Clipboard actions.

  • transfer, setImage, setFileRef, removeFlavors and setFind cover picking from a list, copying one clipboard to another, image and file clipboards, dropping pasteboard types, and the Find pasteboard. They exist mainly for imported Keyboard Maestro macros.

You can also read the clipboard anywhere with the {{clipboard}} token, without a step.

The history and the named clipboards come from the engine's clipboard history module, which is on by default. Without it those operations fail.

Parameters #

ParameterTypeRequiredValuesWhat it does
actionone ofset get clear history deleteHistory setNamed getNamed readNamed copyNamed cutNamed pasteNamed choose transfer setImage setFileRef removeFlavors setFind transform
allyes / noFor deleteHistory, removes the whole history.
filterone oftext links images code colorsFor choose from the history: text, links, images, code or colors. The panel opens on that chip; anything else fails the step. Without it the panel shows everything.
flavorsany value
fromtext
fromIndexwhole number
fromNametext
indexwhole numberWhich history item. 0 is the newest.
intotextThe variable that receives the text, for get, history, getNamed and readNamed.
limitwhole number
macrotextFor transform: the id or name of the macro to transform with.
nametextThe clipboard's name, for the named operations.
opone ofset get clear history deleteHistory setNamed getNamed readNamed copyNamed cutNamed pasteNamed choose transfer setImage setFileRef removeFlavors setFind transformWhich operation, from the list above. Required. action is another spelling.
pathtext
replaceyes / noFor transform: also put the result on the clipboard (marked transient, so the clipboard trigger skips it) and file it in history with the original. On by default when a copy started the run.
sampletextFor get: the text the clipboard held when the Recorder wrote the step. A dry run and a macro test use it instead of the real clipboard.
setyes / noFor history, also puts the item back on the clipboard.
sourceone ofcaptureFor set: capture files the copy in clipboard history as "Capture text" with a viewfinder instead of under the app in front. The Capture text example uses it.
texttextFor transform: the text to transform, or for setNamed the text to keep. transform reads the clipboard when it is left out.
thentext
timeoutnumber
totext
toNametext
valuetextThe text to put on the clipboard, for set, or to keep with setNamed.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Turn the clipboard into lower case. This changes your clipboard when it runs:

Lowercase the clipboard (really changes the clipboard)
Do
  1. Read the clipboard into text
  2. Copy “{{lower(text)}}” to the clipboard
Open in Switchboard to try it

Gotchas #

  • get reads only text. A copied file or picture is not touched by get. set replaces it.

  • In a dry run, get, history and readNamed run normally. Every other operation is skipped.

  • The typeText step's paste method restores your clipboard itself. You do not need to save and restore it around Type text.

Recorded when #

The Recorder writes get into a variable called copied (then copied2, ...) after you copy or cut with ⌘C or ⌘X. It keeps the text it saw (up to 2 KB) in sample. See Recording a macro.

See also #

Type text, Press keys