2 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
Clipboardy is a Node.js library for copying and pasting text and images across various platforms, including macOS, Windows, and Linux. It provides both asynchronous and synchronous methods to interact with the system clipboard. Note that image handling is limited to macOS, and certain operations may not work in headless environments.
If you do, here's more
Clipboardy is a versatile library for accessing the system clipboard across multiple platforms, including macOS, Windows, Linux, OpenBSD, FreeBSD, Android with Termux, and modern browsers. The installation is straightforward with `npm install clipboardy`. You can use it to write and read text asynchronously or synchronously, although synchronous methods are unavailable in browser contexts. The library supports various operations, allowing you to copy text, read it back, and even handle images, albeit with some limitations.
For text operations, you can write to the clipboard asynchronously with `await clipboard.write('๐ฆ')`, which returns a Promise, or use the synchronous version with `clipboard.writeSync('๐ฆ')`. Reading text is equally simple, with `await clipboard.read()` for asynchronous access and `clipboard.readSync()` for synchronous. The library does include some image handling features, but these are limited to macOS. You can write images to the clipboard asynchronously using `await clipboard.writeImages(['/path/to/image.png'])`, but this functionality does not work on other platforms.
Linux users need to note that clipboard operations require a display server (X11 or Wayland). In headless environments, clipboard operations won't work. Clipboardy automatically detects the environment and can fall back to using available tools like `wl-clipboard` or `xsel`. On Windows, it prioritizes native PowerShell cmdlets for clipboard operations, using a bundled binary as a backup if necessary.
Overall, Clipboardy provides a straightforward way to manage clipboard operations across different operating systems, with specific capabilities for text and images where supported. It's a useful tool for developers needing clipboard functionality in their applications.
Questions about this article
No questions yet.