DOCS

Clipboard

You can get and set the clipboard using wa.system.clipboardSet(text) and wa.system.clipboardGet(callback).

wa.system.clipboardGet(function(response){	
	if( response.status != 200 ) return; //an error...
	if( response.available ){ //do we have text?
		wa.log("Clipboard content is " + response.text);
	}

	wa.system.clipboardSet("Hello Jose");
});

The function wa.system.clipboardTextAvailable(callback) can be used to check if the clipboard has text data.

wa.system.clipboardTextAvailable(function(response){	
	if( response.status != 200 ) return; //an error...
	if( response.available ){ //do we have text?
		wa.log("Clipboard has no text");
	}
});

Clipboard formats

Data in the clipboard can be represented in different formats or (data types). Transferring data to and from the clipboard in other formats requires a format specifier (windows) or a UTI (Unifrom Type Identifier) (Mac).

The format specifier is a string. In windows the specifier is the string used when a format is register with RegisterClipboardFormat.

Check for availability of a format

We use wa.system.clipboardDataAvailable(dataType, callback) to check if a given data type (format) is available in the clipboard.

wa.system.clipboardDataAvailable("public.rtf", function(response){
	if( response.status != 200 ) return; //an error...
	if( response.available ){
		console.log("Clipboard has public.rtf");
	}else{
		console.log("Clipboard doesnt have public.rtf");
	}
});

Get data in a particular format

To get a particular data type from the clipboard we use wa.system.clipboardDataGet(dataType, callback). The property available of the response indicates if the particular type is available and it was read from the clipboard.

wa.system.clipboardDataGet("public.rtf", function(response){
	if( response.available ){
		var encodedData = response.encodedData; //the clipboard data encoded as a Base64 string
		var data = window.atob(encodedData)
		console.log("Clipboard content is " + data);
	}
});

Set data in a particular format

To set data of a given type we use wa.system.clipboardDataSet(dataType, data). Where data is either binary data, html, rich-text or your own format.

var htmlData = "<b>Hello Jose</b>"
var format = "public.html"; //UTI for MAC
if( wa.system.targetWindows ) format = "HTML Format"; //for windows

wa.system.clipboardDataSet(format, htmlData);

Some common UTIs to use in Mac are:

"public.text", "public.utf8-plain-text", "public.utf16-plain-text" "public.html", "public.file-url", "public.vcard"

Some format specifiers for Windows are:

"Rich Text Format", "HTML Format", "UniformResourceLocator", "UniformResourceLocatorW", "FileName"


Fork me on GitHub