Core Concepts
Clipboard
Copy text to and read text from the system clipboard for automation workflows.
What you can do
Copy Text
Copy text to the system clipboard
clipboard.setContent(text)Read Text
Read the current text content from the system clipboard
clipboard.getContent()Quick Reference
setContent
clipboard.setContent(text: string)Copy a given text to the system clipboard
getContent
clipboard.getContent()Read the current text content of the system clipboard
Copying Text
Use setContent to copy text to the system clipboard. This is equivalent to a user pressing Ctrl+C / Cmd+C after selecting text.
import { clipboard } from "@nut-tree/nut-js";
// Copy text to the clipboard
await clipboard.setContent("Hello, world!");Reading Text
Use getContent to retrieve the current text stored in the system clipboard.
import { clipboard } from "@nut-tree/nut-js";
// Read clipboard content
const content = await clipboard.getContent();
console.log(content);Text Only
Examples
Paste Text into a Field
Set clipboard content and paste it using keyboard shortcuts
Scenario: You need to enter a long string into an input field quickly.
import { clipboard, keyboard, Key } from "@nut-tree/nut-js";
// Copy the text to clipboard
await clipboard.setContent("user@example.com");
// Paste it using keyboard shortcut
await keyboard.pressKey(Key.LeftControl, Key.V);
await keyboard.releaseKey(Key.LeftControl, Key.V);Read and Verify Clipboard
Capture selected text via clipboard for verification
Scenario: You want to verify that a UI element contains the expected text.
import { clipboard, keyboard, Key } from "@nut-tree/nut-js";
// Select all text in the focused field
await keyboard.pressKey(Key.LeftControl, Key.A);
await keyboard.releaseKey(Key.LeftControl, Key.A);
// Copy selection to clipboard
await keyboard.pressKey(Key.LeftControl, Key.C);
await keyboard.releaseKey(Key.LeftControl, Key.C);
// Read and check the content
const content = await clipboard.getContent();
console.log("Field contains:", content);Transfer Text Between Applications
Use the clipboard to move data between apps
Scenario: You need to copy a value from one application and paste it into another.
import { clipboard, keyboard, Key } from "@nut-tree/nut-js";
// Copy from source application (assuming text is already selected)
await keyboard.pressKey(Key.LeftControl, Key.C);
await keyboard.releaseKey(Key.LeftControl, Key.C);
// Read what was copied
const data = await clipboard.getContent();
console.log("Copied:", data);
// ... switch to target application ...
// Paste into target
await keyboard.pressKey(Key.LeftControl, Key.V);
await keyboard.releaseKey(Key.LeftControl, Key.V);Next Steps
Now that you understand clipboard operations, learn about the different ways to search for content on screen: