클립보드
시스템 클립보드에서 복사 및 붙여넣기 작업을 수행한다.
리눅스에서는 selection
클립보드도 존재한다. 이를 조작하려면 각 메서드에 selection
을 전달해야 한다:
const { clipboard } = require('electron')
clipboard.writeText('Example string', 'selection')
console.log(clipboard.readText('selection'))
메서드
clipboard
모듈은 다음과 같은 메서드를 제공한다:
참고: 실험적인 API는 별도로 표시하며, 향후 제거될 가능성이 있다.
clipboard.readText([type])
type
string (선택 사항) -selection
또는clipboard
로 설정할 수 있으며, 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
반환값 string
- 클립보드에 있는 내용을 일반 텍스트로 반환한다.
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])
text
stringtype
string (선택 사항) -selection
또는clipboard
로 설정 가능. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용할 수 있다.
주어진 text
를 클립보드에 일반 텍스트로 저장한다.
const { clipboard } = require('electron')
const text = 'hello i am a bit of text!'
clipboard.writeText(text)
clipboard.readHTML([type])
type
string (선택 사항) -selection
또는clipboard
중 하나를 선택할 수 있다. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
string
을 반환한다 - 클립보드에 있는 내용을 마크업 형태로 가져온다.
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])
markup
stringtype
string (선택 사항) -selection
또는clipboard
로 설정 가능. 기본값은 'clipboard'.selection
은 Linux에서만 사용할 수 있다.
클립보드에 markup
을 기록한다.
const { clipboard } = require('electron')
clipboard.writeHTML('<b>Hi</b>')
clipboard.readImage([type])
type
string (선택 사항) -selection
또는clipboard
값을 가질 수 있다. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
NativeImage
를 반환한다. 클립보드에 있는 이미지 내용을 가리킨다.
clipboard.writeImage(image[, type])
image
NativeImagetype
string (옵션) -selection
또는clipboard
중 하나를 선택할 수 있으며, 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
이미지를 클립보드에 쓴다.
clipboard.readRTF([type])
type
string (선택 사항) -selection
또는clipboard
중 하나를 지정할 수 있다. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
반환값 string
- 클립보드에 있는 내용을 RTF 형식으로 반환한다.
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])
text
stringtype
string (선택사항) -selection
또는clipboard
로 지정할 수 있으며, 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
RTF 형식으로 text
를 클립보드에 쓴다.
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
Object
를 반환한다:
title
stringurl
string
클립보드에 있는 북마크를 나타내는 title
과 url
키를 포함한 객체를 반환한다. 북마크를 사용할 수 없는 경우 title
과 url
값은 빈 문자열이 된다. 윈도우에서는 title
값이 항상 빈 문자열이다.
clipboard.writeBookmark(title, url[, type])
macOS Windows
title
string - Windows에서는 사용되지 않음url
stringtype
string (선택 사항) -selection
또는clipboard
중 하나로 설정 가능. 기본값은 'clipboard'.selection
은 Linux에서만 사용 가능.
title
(macOS 전용)과 url
을 클립보드에 북마크로 저장한다.
참고: Windows의 대부분 애플리케이션은 클립보드에 북마크를 붙여넣는 기능을 지원하지 않는다. 따라서 clipboard.write
를 사용해 북마크와 대체 텍스트를 함께 클립보드에 저장할 수 있다.
const { clipboard } = require('electron')
clipboard.writeBookmark('Electron Homepage', 'https://electronjs.org')
clipboard.readFindText()
macOS
string
타입의 값을 반환한다. 이 값은 활성화된 애플리케이션의 찾기 패널 현재 상태 정보를 담고 있는 찾기 클립보드에서 가져온 텍스트이다.
이 메서드는 렌더러 프로세스에서 호출될 때 동기식 IPC를 사용한다. 애플리케이션이 활성화될 때마다 찾기 클립보드의 캐시된 값을 다시 읽어온다.
clipboard.writeFindText(text)
macOS
text
string
text
를 일반 텍스트로 찾기 클립보드에 기록한다. 찾기 클립보드는 활성 애플리케이션의 찾기 패널 현재 상태 정보를 담고 있다. 이 메서드는 렌더러 프로세스에서 호출될 때 동기식 IPC를 사용한다.
clipboard.clear([type])
type
string (선택 사항) -selection
또는clipboard
값을 가질 수 있다. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
클립보드의 내용을 지운다.
clipboard.availableFormats([type])
type
string (선택 사항) -selection
또는clipboard
로 설정할 수 있다. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
string[]
을 반환한다 - 클립보드 type
에 대해 지원되는 포맷의 배열이다.
const { clipboard } = require('electron')
const formats = clipboard.availableFormats()
console.log(formats)
// [ 'text/plain', 'text/html' ]
clipboard.has(format[, type])
실험적 기능
format
stringtype
string (선택 사항) -selection
또는clipboard
를 지정할 수 있다. 기본값은 'clipboard'이다.selection
은 Linux에서만 사용 가능하다.
boolean
을 반환한다. 클립보드가 지정된 format
을 지원하는지 여부를 나타낸다.
const { clipboard } = require('electron')
const hasFormat = clipboard.has('public/utf8-plain-text')
console.log(hasFormat)
// 'true' 또는 'false'
clipboard.read(format)
실험적 기능
format
string
string
을 반환한다. 클립보드에서 format
타입의 데이터를 읽어온다.
format
은 유효한 ASCII 문자를 포함해야 하며 /
구분자를 사용해야 한다.
a/c
, a/bc
는 유효한 형식이지만, /abc
, abc/
, a/
, /a
, a
는 유효하지 않다.
clipboard.readBuffer(format)
실험적 기능
format
string
Buffer
를 반환한다 - 클립보드에서 format
타입의 데이터를 읽어온다.
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])
실험적 기능
format
stringbuffer
Buffertype
string (선택 사항) -selection
또는clipboard
로 설정 가능; 기본값은 'clipboard'이다.selection
은 Linux에서만 사용할 수 있다.
buffer
를 format
형식으로 클립보드에 쓴다.
const { clipboard } = require('electron')
const buffer = Buffer.from('writeBuffer', 'utf8')
clipboard.writeBuffer('public/utf8-plain-text', buffer)
clipboard.write(data[, type])
data
Objecttext
string (선택 사항)html
string (선택 사항)image
NativeImage (선택 사항)rtf
string (선택 사항)bookmark
string (선택 사항) -text
에 있는 URL의 제목.
type
string (선택 사항) -selection
또는clipboard
로 설정 가능; 기본값은 'clipboard'.selection
은 Linux에서만 사용 가능.
data
를 클립보드에 쓴다.
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' }