clipboard
Ausführung von Kopier- und Einfüge-Operationen von der Zwischenablage des Betriebssystems.
Process: Main, Renderer (non-sandboxed only)
Unter Linux gibt es auch eine selection Zwischenablage. Zum Bearbeiten müssen Sie selection an jede Methode übergeben:
const { clipboard } = require('electron')
clipboard.writeText('Example string', 'selection')
console.log(clipboard.readText('selection'))
Methoden
Das clipboard Modul besitzt die folgenden Methoden:
Notiz: Experimentelle Schnittstellen sind mit "Experimentell" markiert und könnten in der Zukunft wegfallen.
clipboard.readText([type])
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Gibt einen string zurück - Der Inhalt der Zwischenablage liegt in Klartext vor.
const { clipboard } = require('electron')
clipboard.writeText('hello i am a bit of text!')
const text = clipboard.readText()
console.log(text)
// hello i am a bit of text!'
clipboard.writeText(text[, type])
textstringtypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Schreibt den text als Klartext in die Zwischenablage.
const { clipboard } = require('electron')
const text = 'hello i am a bit of text!'
clipboard.writeText(text)
clipboard.readHTML([type])
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Gibt einen string zurück - Der Inhalt der Zwischenablage liegt in Auszeichnungssprache (markup language) vor.
const { clipboard } = require('electron')
clipboard.writeHTML('<b>Hi</b>')
const html = clipboard.readHTML()
console.log(html)
// <meta charset='utf-8'><b>Hi</b>
clipboard.writeHTML(markup[, type])
markupstringtypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Schreibt markup in die Zwischenablage.
const { clipboard } = require('electron')
clipboard.writeHTML('<b>Hi</b>')
clipboard.readImage([type])
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Returns NativeImage - The image content in the clipboard.
clipboard.writeImage(image[, type])
imageNativeImagetypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Schreibt das image in die Zwischenablage.
clipboard.readRTF([type])
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Gibt einen string zurück - Der Inhalt der Zwischenablage liegt im Rich Text Format (RTF) vor.
const { clipboard } = require('electron')
clipboard.writeRTF('{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}')
const rtf = clipboard.readRTF()
console.log(rtf)
// {\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}
clipboard.writeRTF(text[, type])
textstringtypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Schreibt den text im Rich Text Format (RTF) in die Zwischenablage.
const { clipboard } = require('electron')
const rtf = '{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}'
clipboard.writeRTF(rtf)
clipboard.readBookmark() macOS Windows
Gibt das Object zurück:
titlestringurlstring
Gibt ein Objekt, dass die Keys title und url enthält zurück. Diese Keys repräsentieren das Lesezeichen in der Zwischenablage. Wenn das Lesezeichen nicht verfügbar ist, sind die Werte title und url leer. The title value will always be empty on Windows.
clipboard.writeBookmark(title, url[, type]) macOS Windows
titlestring - Unused on Windowsurlstringtypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Writes the title (macOS only) and url into the clipboard as a bookmark.
Hinweis: Die meisten Apps unter Windows unterstützen das Einfügen von Lesezeichen nicht in sie, sodass Sie clipboard.write verwenden können, um sowohl ein Lesezeichen als auch einen Fallbacktext in die Zwischenablage zu schreiben.
const { clipboard } = require('electron')
clipboard.writeBookmark('Electron Homepage', 'https://electronjs.org')
clipboard.readFindText() macOS
Returns string - The text on the find pasteboard, which is the pasteboard that holds information about the current state of the active application’s find panel.
This method uses synchronous IPC when called from the renderer process. The cached value is reread from the find pasteboard whenever the application is activated.
clipboard.writeFindText(text) macOS
textstring
Writes the text into the find pasteboard (the pasteboard that holds information about the current state of the active application’s find panel) as plain text. This method uses synchronous IPC when called from the renderer process.
clipboard.clear([type])
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Löscht den Inhalt aus der Zwischenablage.
clipboard.availableFormats([type])
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Gibt ein string[] zurück - Ein Array mit allen von der Zwischenablage unterstützten Formattypen type.
const { clipboard } = require('electron')
const formats = clipboard.availableFormats()
console.log(formats)
// [ 'text/plain', 'text/html' ]
clipboard.has(format[, type]) Experimentell
formatstringtypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Gibt einen boolean zurück - Prüft, ob die Zwischenablage das angegebene format unterstützt.
const { clipboard } = require('electron')
const hasFormat = clipboard.has('public/utf8-plain-text')
console.log(hasFormat)
// 'true' or 'false'
clipboard.read(format) Experimentell
formatstring
Gibt den string zurück - Liest den format Typ von der Zwischenablage.
format should contain valid ASCII characters and have / separator. a/c, a/bc are valid formats while /abc, abc/, a/, /a, a are not valid.
clipboard.readBuffer(format) Experimentell
formatstring
Gibt den Buffer zurück - Liest den format Typ von der Zwischenablage.
const { clipboard } = require('electron')
const buffer = Buffer.from('this is binary', 'utf8')
clipboard.writeBuffer('public/utf8-plain-text', buffer)
const ret = clipboard.readBuffer('public/utf8-plain-text')
console.log(buffer.equals(ret))
// true
clipboard.writeBuffer(format, buffer[, type]) Experimentell
formatstringbufferPuffertypestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Schreibt den buffer mit dem angegebenen format in die Zwischenablage.
const { clipboard } = require('electron')
const buffer = Buffer.from('writeBuffer', 'utf8')
clipboard.writeBuffer('public/utf8-plain-text', buffer)
clipboard.write(data[, type])
dataObjecttextstring (optional)htmlstring (optional)imageNativeImage (optional)rtfstring (optional)bookmarkstring (optional) - The title of the URL attext.
typestring (optional) - Can beselectionorclipboard; default is 'clipboard'.selectionist nur unter Linux verfügbar.
Schreibt data in die Zwischenablage.
const { clipboard } = require('electron')
clipboard.write({
text: 'test',
html: '<b>Hi</b>',
rtf: '{\\rtf1\\utf8 text}',
bookmark: 'a title'
})
console.log(clipboard.readText())
// 'test'
console.log(clipboard.readHTML())
// <meta charset='utf-8'><b>Hi</b>
console.log(clipboard.readRTF())
// '{\\rtf1\\utf8 text}'
console.log(clipboard.readBookmark())
// { title: 'a title', url: 'test' }