I am running OpenSuse Leap 15.1 with 64-bit Thunderbird 60.8.0. I am trying the simplest of tasks, to read and print the clipboard. The code is:
var paste = readFromClipboard(); if(!paste) return;GetCurrentEditor().insertText(paste)
I get nothing. Do I have to give javascript permission to read the clipboard?
Thanks
Durado keyconfig print clipboard
-
- Posts: 2
- Joined: October 9th, 2019, 7:33 pm
Re: Durado keyconfig print clipboard
The command goDoCommand("cmd_paste") does what the original code failed to do; prints the content of the clipboard. Is there a way to save the output of the command to a string?
-
- Posts: 6421
- Joined: February 3rd, 2009, 6:29 pm
Re: Durado keyconfig print clipboard
Try this:MatchpointOK wrote:Is there a way to save the output of the command to a string?
Code: Select all
function readFromClipboard() {
var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
var transferable = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
var flavor = "text/unicode";
transferable.init(null);
transferable.addDataFlavor(flavor);
clipboard.getData(transferable, clipboard.kGlobalClipboard);
var data = {};
try {
transferable.getTransferData(flavor, data);
} catch (e) {
return null; // no data available for given flavor
}
if (!data.value) {
return null; // no data available
}
data = data.value.QueryInterface(Components.interfaces.nsISupportsString);
return data.data;
}
var paste = readFromClipboard();
alert(paste);