tauri-plugin-clipboard-next
Tauri 2 clipboard plugin: read/write/listen to clipboard (text/image/RTF/HTML/files) on Windows/macOS/Linux/iOS.
FEATURE SUPPORT
- Plain text
- Html
- Rich text
- Image (In
PNGformat) - File (In
file-uri-listformat) - Watch clipboard changes
Platform Support
| Platform | Supported |
|---|---|
| Windows | ✅ |
| macOS | ✅ |
| Linux | ✅ |
| iOS(Beta) | ✅ |
| Android | 🚧 |
Install
cargo add tauri-plugin-clipboard-next
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
pnpm add tauri-plugin-clipboard-next-api
Usage
src-tauri/src/lib.rs
pub fn run() {
tauri::Builder::default()
+ .plugin(tauri_plugin_clipboard_next::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
src-tauri/capabilities/default.json
{
...
"permissions": [
...
+ "clipboard-next:default"
]
}
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
import { startWatch, onClipboardChange } from 'tauri-plugin-clipboard-next-api';
await startWatch();
const unlisten = await onClipboardChange((clipboard) => {
console.log('Clipboard changed:', clipboard);
});
// Later, to stop listening
unlisten();
Methods
| Method | Description |
|---|---|
startWatch |
Start listening for clipboard changes |
stopWatch |
Stop listening for clipboard changes |
hasText |
Check if the clipboard contains plain text |
hasRtf |
Check if the clipboard contains rich text |
hasHtml |
Check if the clipboard contains html |
hasImage |
Check if the clipboard contains an image |
hasFiles |
Check if the clipboard contains files |
readText |
Read plain text from the clipboard |
readRtf |
Read rich text from the clipboard |
readHtml |
Read html from the clipboard |
readImage |
Read image from the clipboard |
readFiles |
Read file paths from the clipboard |
writeText |
Write plain text to the clipboard |
writeRtf |
Write rich text to the clipboard |
writeHtml |
Write html content to the clipboard |
writeImage |
Write an image to the clipboard from a file path |
writeFiles |
Write file paths to the clipboard |
clear |
Clear the clipboard contents |
getFilePath |
Get the file path for clipboard operations |
readClipboard |
Read all available content from the clipboard |
onClipboardChange |
Listen for clipboard changes |
Example
git clone https://github.com/zhoushi1/tauri-plugin-clipboard-next.git
pnpm install
pnpm build
cd examples/tauri-app
pnpm install
pnpm tauri dev
Thanks
- Special thanks to the clipboard-rs crate, which provides reliable cross-platform clipboard operation capabilities for this Tauri 2 plugin (supporting text, image, rich text, HTML and files).