add text to clipboard via real JavaScript

Seems there is not an option to add a text to clipboard via real JavaScript yet, can this be added? Thanks a lot.

You can do it e.g. like this:

(async () => {
let shellScript = `echo "YOUR TEXT HERE" | pbcopy`;


let shellScriptWrapper = {
    script: shellScript
};


let result = await runShellScript(shellScriptWrapper);
returnToBTT(result);

})();

Thanks a lot Andreas.
You can move this post to "Discussion" board as it's already supported.

BTW, I find it doesn't work with functions which has Japanese chars. Do you know why?

code below add nothing to clipboard.

(async() => {

function combine(a, b) {
    return a + " " + b;
}

let result = combine("2021", "こんばんは");

let shellScript = "echo " + result + "| pbcopy";
let shellScriptWrapper = {
    script: shellScript
};
await runShellScript(shellScriptWrapper);

returnToBTT("");

})()

The code in this example will produce a shell script like this:

"echo 2021 こんばんは| pbcopy", the white space breaks things.

This code should work fine:

(async() => {

function combine(a, b) {
    return a + " " + b;
}

let result = combine("2021","こんばんは");

let shellScript = `printf "${result}" | LANG=en_US.UTF-8 pbcopy`;
let shellScriptWrapper = {
    script: shellScript
};
await runShellScript(shellScriptWrapper);

returnToBTT(shellScript);
})()

Additionally it might be necessary to specify that it is using utf8 encoding (see above)

Thanks a lot Andreas.
I tried it and find the key is UTF-8. In other words, the code below works for me.

(async() => {

function combine(a, b) {
    return a + " " + b;
}

let result = combine("2021", "こんばんは");

let shellScript = "echo " + result + "| LANG=en_US.UTF-8 pbcopy";
let shellScriptWrapper = {
    script: shellScript
};
await runShellScript(shellScriptWrapper);

returnToBTT("");

})()

Imprint | Privacy Policy