simple-mac-clipboard
v1.2.4
Published
simple mac clipboard for node & electron
Downloads
958
Maintainers
Readme
simple-mac-clipboard
simple mac clipboard for node & electron
Install
$ pnpm add simple-mac-clipboardRelated
https://github.com/electron/electron/issues/9035
API
based on https://developer.apple.com/documentation/appkit/nspasteboard
const clip = require('simple-mac-clipboard')Note
- for read & write, format is required, and format is always the first argument
- for write, the boolean return value is for success or not, map from objc
YESorNO
clear
export function clear(): voidclear the clipboard
read
// single item
export function readBuffer(format: string): Buffer
export function readText(format: string): string
// items
export function readBuffers(format: string): Buffer[]
export function readTexts(format: string): string[]write
// single item
export function writeBuffer(format: string, data: Buffer): boolean
export function writeText(format: string, text: string): boolean
// items
export function writeBuffers(format: string, data: Buffer[]): boolean
export function writeTexts(format: string, text: string[]): booleanpredefined Formats
FORMAT_PLAIN_TEXT / FORMAT_FILE_URL / FORMAT_SOURCE_APP_BUNDLE_ID
read/write File Paths
import { FORMAT_FILE_URL, readTexts, writeTexts } from 'simple-mac-clipboard'
import { fileURLToPath, pathToFileURL } from 'node:url'
const filePaths = ['/tmp/a/b.txt', '/tmp/c']
// write
writeTexts(
FORMAT_FILE_URL,
filePaths.map((p) => pathToFileURL(p).href),
)
// read
console.log(readTexts(FORMAT_FILE_URL).map((u) => fileURLToPath(u)))Changelog
License
the MIT License http://magicdawn.mit-license.org
