MozillaZine

Durado keyconfig print clipboard

Announce and Discuss the Latest Theme and Extension Releases.
MatchpointOK
 
Posts: 2
Joined: October 9th, 2019, 7:33 pm

Post Posted October 9th, 2019, 7:44 pm

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

MatchpointOK
 
Posts: 2
Joined: October 9th, 2019, 7:33 pm

Post Posted October 11th, 2019, 5:40 pm

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?

morat
 
Posts: 3744
Joined: February 3rd, 2009, 6:29 pm

Post Posted November 25th, 2019, 8:56 pm

MatchpointOK wrote:Is there a way to save the output of the command to a string?

Try this:

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);

Return to Extension/Theme Releases


Who is online

Users browsing this forum: No registered users and 3 guests