clipboard-sys
v1.2.1
Published
Cross platform node system clipboard work with text, image, files
Downloads
1,804
Maintainers
Readme
clipboard-sys
Access the system clipboard
- copy/paste text
- copy/paste image
- copy/paste files
Cross-platform!
Supports:
- Windows
- Linux (xclip supporting systems) should be installed xclip (
sudo apt-get install xclip
) - MacOS
Install
npm install clipboard-sys
Usage
import { clipboard } from './index';
import fs from 'fs';
async function readWriteText() {
await clipboard.writeText('some text');
console.log('text from clipboard:', await clipboard.readText());
}
readWriteText();
async function readWriteImage() {
await clipboard.writeImage('./source.png');
await clipboard.readImage('./destination.png');
await clipboard.writeImage(fs.readFileSync('./source.png')); //buffer
return await clipboard.readImage(); //buffer
}
readWriteImage();
async function copyFiles() {
await clipboard.writeFiles('./source1.txt', './source2.png');
console.log(await clipboard.readFiles());
}
copyFiles();
async function pasteFiles() {
await clipboard.pasteFiles('Copy', './destinationFolder', './source1.png', './source2.png');
await clipboard.pasteFiles('Cut', './destinationFolder', './source1.png', './source2.png');
}
pasteFiles();
API
export interface SysClipboard {
readText(): Promise<string>;
writeText(text: string): Promise<void>;
readImage(file?: string): Promise<Buffer>;
writeImage(file: string | Buffer): Promise<void>;
readFiles(): Promise<Array<string>>;
pasteFiles(action: 'Copy' | 'Cut', destinationFolder: string, ...files: Array<string>): Promise<void>;
writeFiles(...files: Array<string>): Promise<boolean>;
}
Contribution
Opened for contribution https://github.com/udarrr/clipboard-sys