Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Paste text from clipboard

  • Paste text from clipboard

    Posted by Tudor Baican on June 4, 2024 at 11:14 pm

    Hello Friends,

    I wand to paste some text from my clipboard through a script.

    I use pbpaste for that and it works fine.

    var pasteText = system.callSystem(“pbpaste”)

    But some character are not supported like ș or ş … and I get some question mark instead.

    Do you know a work around for that?

    Thanks


    Tudor Baican replied 1 year, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Walter Soyka

    June 5, 2024 at 1:01 am

    I think your problem is that your text uses Unicode encodings, but something somewhere between pbpaste, stdin, and ExtendScript is treating the string as ASCII.

    The best workaround I can think of is to explicitly tell pbpaste to use a Unicode encoding, dump it to a file, and explicitly read the file back in with a Unicode encoding.

    Sample code:

    // create a temporary file

    var tempFile = new File("~/TempUnicodeText-" + Date.now());

    // pbpaste uses the LANG environment variable to determine its encoding

    // we'll explicitly set it for a UTF-8 encoding, then dump the clipboard to a file

    system.callSystem("export LANG=en_US.UTF-8 && pbpaste > " + tempFile.fsName);

    // let's explictly decode our new file with UTF-8, read in the contents,

    // and then delete the temporary file

    tempFile.encoding = "UTF8";

    tempFile.open();

    var pasteText = tempFile.read();

    tempFile.close();

    tempFile.remove();

    // now pasteText holds our Unicode-encoded string,

    // and we can do whatever we want with it

    alert(pasteText);

  • Tudor Baican

    June 5, 2024 at 9:10 pm

    Walter, lot of thanks!! you saved me 🙂

    It’s a bit annoying that it doesn’t work by default but sometime small details are just laborious.

    I will implement your workaround and tell you.

    Thanks again!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy