Clipboard

Native clipboard.

Modulerequire("gui")
TypeObject

The Clipboard class can not be created by user, its instance can only be recevied by using the factory methods.

// Get the default copy-paste clipboard.
const clipboard = gui.Clipboard.get()

// Changing the content of clipboard with multiple formats of data.
clipboard.setData([
  {type: 'text', value: 'some text'},
  {type: 'html', value: '<strong>some text</strong>'},
  {type: 'image', value: gui.Image.createFromPath('...')},
  {type: 'file-paths', value: ['/some/path']},
])

// Read data.
const data = clipboard.getData('text')
if (data.type == 'text')
  console.log(data.value)

Class methods

get()

Return the default copy-paste clipboard.

Return

Clipboard

fromType(type)

Return the clipboard with type.

Parameters

Return

Clipboard

Methods

clear()

Clear the clipboard.

setText(text)

Set text as clipboard's content.

Parameters

getText()

Return the content of clipboard as text.

Return

String

isDataAvailable(type)

Return whether the data of type is available.

Parameters

Return

Boolean

getData(type)

Get the data of type from clipboard.

You should always check the type of returned data before using it.

Parameters

Return

Clipboard::Data

setData(objects)

Set clipboard's content.

Parameters

startWatching()

Start watching clipboard's content.

The onChange event will be emitted when clipboard's content has been changed.

On macOS, due to lack of system notifications for clipboard events, this event is implemented by polling every 500ms.

stopWatching()

Stop watching clipboard's content.

Events

onChange(self)

Emitted when clipboard's content has been changed.

The startWatching method must be called first to make this event work.

Parameters

Preventable

No.