new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

clipboard/methods

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

clipboard.readText() method

clipboard.readText() returns Promise<string>. It resolves with the content of the clipboard as plain text, modeled after the W3C navigator.clipboard.readText API.

clipboard.writeText(text) method

clipboard.writeText(text) accepts a string parameter and returns Promise<void>. It resolves once the text has been written to the clipboard, modeled after the W3C navigator.clipboard.writeText API.

clipboard.read() method

clipboard.read() returns Promise<ClipboardItem[]>. It resolves with an array of ClipboardItem objects containing the clipboard's contents.

clipboard.write(data) method

clipboard.write(data) accepts an array of ClipboardItem instances constructed via new ClipboardItem({ [mime]: payload }) and returns Promise<void>. It resolves once the data has been written to the clipboard. All entries supplied in a single write() call are committed to the system clipboard atomically.

clipboard.has(mimetype) method

clipboard.has(mimetype) accepts a string MIME type to check and returns Promise<boolean>. It resolves with true if the clipboard contains data of the specified MIME type, otherwise false. For raw formats, use the electron application/osclipboard custom format with format parameter, for example: 'electron application/osclipboard;format="public/utf8-plain-text"'.

clipboard.clear() method

clipboard.clear() clears the clipboard content.

clipboard.writeText() example

const { clipboard } = require('electron') async function writeClipboardText () { await clipboard.writeText('hello i am a bit of text!') } writeClipboardText()

clipboard.read() example

const { clipboard } = require('electron') async function dumpClipboard () { const items = await clipboard.read() for (const item of items) { for (const type of item.types) { const blob = await item.getType(type) console.log(type, blob) } } } dumpClipboard()

clipboard.write() example with multiple formats

const { clipboard, ClipboardItem, nativeImage } = require('electron') const png = nativeImage.createFromPath('/path/to/icon.png').toPNG() async function writeClipboard () { await clipboard.write([ new ClipboardItem({ 'text/plain': 'hello', 'text/html': '<b>hello</b>', 'image/png': new Blob([png], { type: 'image/png' }), 'electron application/bookmark': { title: 'Electron', url: 'https://electronjs.org' } }) ]) } writeClipboard()

clipboard.write() example with web custom format

const { clipboard, ClipboardItem } = require('electron') async function writeClipboard () { await clipboard.write([ new ClipboardItem({ 'web application/x.my-app-clip': new Blob(['arbitrary payload']) }) ]) } writeClipboard()

clipboard.has() example

const { clipboard } = require('electron') async function check () { const hasFormat = await clipboard.has('text/html') console.log(hasFormat) // 'true' or 'false' const rawFormat = 'electron application/osclipboard;format="public/utf8-plain-text"' const hasRawFormat = await clipboard.has(rawFormat) } check()

Give your agent this brain