Skip to content

Instantly share code, notes, and snippets.

@RemcoSchellekensNS
Created February 27, 2023 15:37
Show Gist options
  • Save RemcoSchellekensNS/c840313d9166ee2dde5be8b878c1668a to your computer and use it in GitHub Desktop.
Save RemcoSchellekensNS/c840313d9166ee2dde5be8b878c1668a to your computer and use it in GitHub Desktop.
#jarchi script example using clipboard for text exchange
/*
* New Archi Script
*/
// Places string on clipboard
function SetClipboardString(string) {
var Toolkit = Java.type("java.awt.Toolkit");
var Transferable = Java.type("java.awt.datatransfer.StringSelection");
try {
var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
transferable = new Transferable(string);
clipboard.setContents(transferable, transferable);
}
catch (e) {
console.log("Failed copy string " + string + " to the clipboard due to exception: " + e);
}
}
// Returns content of clipboard, if it contains any text in plain text format
function GetClipboardString() {
var Toolkit = Java.type("java.awt.Toolkit");
var DataFlavor = Java.type("java.awt.datatransfer.DataFlavor");
var t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
var txt = t.getTransferData(DataFlavor.stringFlavor);
return txt;
}
} catch (e) {
console.log("getClipboardString exception: " + e);
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment