AutoControl Control your browser your way Forum               Install now from theChrome Web Store

ACtl.setClipboard


Puts content in the clipboard in the specified format. ACtl.setClipboard(content) ACtl.setClipboard({image:}) ACtl.setClipboard({html:[,sourceURL:]}) content It can be any of the types below. Each type determines what data format is put in the clipboard.
string The string is put as plain text.
Element
DocumentFragment
The HTML is put as formatted text.
HTMLImageElement
SVGImageElement
HTMLCanvasElement
OffscreenCanvas
The image content is put as a bitmap
Array of paths Each path is put as a file/folder. You must ensure these paths point to existing files/folders, otherwise the operating system will complain when you try to paste them.
image Type: string An image to put in the clipboard. It can be a data URI or a binary string in PNG, JPEG or BMP format. html Type: string HTML code to put in the clipboard as formatted text. sourceURL Type: string Default: undefined The URL from which the HTML was "copied" (figuratively speaking, of course, as in this case the HTML is being put in the clipboard programmatically). Returns Type: Promise Resolves to: boolean Returns immediately. The Promise will resolve with true if the content was put in the clipboard successfully. false otherwise. Throws Type: string Error description if the argument passed doesn't match any recognizable form.

Examples

Put plain text.

	ACtl.setClipboard('Hello, world!') ;
	

Put formatted text.

	//When you paste this text in any text field that supports
	//formatted text, you'll get blue text in large Arial font.
	ACtl.setClipboard({html: '<font size=6 color=blue face=Arial>Hello</font>'}) ;
	

Put an entire webpage in the clipboard as hypertext.

	//This script must run in the page you want to copy
	if( await ACtl.setClipboard( document.body ) )
		alert('Webpage copied successfully') ;
	else
		alert('Copy operation failed') ;
	

Put a file.

	//This file can then be pasted in any place that accepts files,
	//like a file explorer, a file editor, etc.
	ACtl.setClipboard(['C:/Pictures/Photo.jpg']) ;
	

Put two files and a folder.

	let files = [
		'C:/Pictures/Photo1.jpg',
		'C:/Pictures/Photo2.jpg',
		'C:/Pictures/Vacations',
	] ;
	ACtl.setClipboard(files) ;
	

Read an image file from disk and put the image content (not the file) in the clipboard.

	//Get the image file as a binary string
	let fileContent = await ACtl.getFile('C:/Pictures/Photo.jpg', 'binary') ;
	//Put the file content as an image 
	ACtl.setClipboard({image: fileContent}) ;
	
Scripting API Script Isolation Asynchronicity Backgrnd Scripts GUI vs API ACtl.include ACtl.import ACtl.getFile ACtl.saveFile ACtl.saveURL ACtl.openURL ACtl.closeTab ACtl.runInTab ACtl.runInFrames ACtl.runInPageCtx ACtl.getTabInfo ACtl.getTabIds ACtl.TAB_ID ACtl.setTabState ACtl.captureTab ACtl.execAction ACtl.runCommand ACtl.getClipboard ACtl.setClipboard ACtl.expand ACtl.switchState ACtl.var ACtl.pubVar ACtl.on ACtl.off ACtl.sleep ACtl.STOP_CHAIN ACtl.STOP_FULL_SEQ