Skip to main content
levi23
Known Participant
September 6, 2016
Question

copy text to the clipboard or retrieve text from the clipboard.

  • September 6, 2016
  • 1 reply
  • 847 views

Hello everyone. I would ask if it is possible to copy a text to the clipboard content from a javascript illustrator.

I also like to do the operation in reverse. retrieve text from the clipboard as a variable to use.

I have read on the Internet could be done by Bat or AppleScript files but I have been tested and have not gotten it to work.

It could run both Windows and Mac? It is possible?

I would appreciate any help. Keep looking information

Many thanks

a greeting

This topic has been closed for replies.

1 reply

levi23
levi23Author
Known Participant
September 11, 2016

Hello such.

I've been looking information and have found a method that should work, but I'm not able to do.

The process would create a txt file and a file ejectutable (MAC) (command ?? sh?) And using this file created dynamically txt copy the contents to clipboard

Could anyone help me, please?

I am a novice in these matters, and even more in what refers to MAC

I guess it would be like a windows bat file, but I searched information but I do not know how to dynamically create and run it on Mac

I would appreciate any help.

Thank you very much.

A greeting. Excuse my English

var doc = app.activeDocument;

var text = doc.textFrames[0].contents;

//alert(text)

copyTextToClipboard2(text)

function copyTextToClipboard2(text){

    var folderForTempFiles = '~/Desktop';

    var clipTxtFile = new File(folderForTempFiles + "/ClipBoardMac.txt");

    clipTxtFile.open('w');

    clipTxtFile.encoding = "UTF-8";

    clipTxtFile.lineFeed = "Unix";

    clipTxtFile.write(text);

    clipTxtFile.close();

    var clipBatFile = new File(folderForTempFiles + "/ClipBoard.command");

    if (clipBatFile.exists) {

        clipBatFile.remove();

    }

    clipBatFile.open('w');

    //clipBatFile.writeln("cat \"" + folderForTempFiles + "/ClipBoard.txt\"|clip");

    //clipBatFile.write("cat " + folderForTempFiles + " | pbcopy");

    clipBatFile.writeln("#!/bin/bash"+"\n"+"cat " + folderForTempFiles + "/ClipBoardMac.txt" + " | pbcopy");

    clipBatFile.close();

    clipBatFile.execute();

}

Ten A
Community Expert
Community Expert
September 11, 2016

Why don't you use copy and paste methods like below?

function copytxt(){

  if (app.selection.length==1&&app.selection[0].typename=="TextFrame")

  app.copy();

  }

function getclipboardtxt(){

  app.paste();

  var tx = app.activeDocument.textFrames[0].contents;

  app.activeDocument.textFrames[0].remove();

  return tx;

  }

levi23
levi23Author
Known Participant
September 12, 2016

thanks for your answer but my intent is to copy the unformatted text

a greeting