I need a cross-platform way to copy from Extendscript to the system clipboard, any system clipboard.
puzzlingly, Extendscript doesn't allow this. Every language I've programmed in allows this. Strange.
I have two work-arounds:
1)
I can put the text on a textlayer and then copy it to the clipboard with: app.executeCommand(app.findMenuCommandId("Copy"));
But to do that the text has to be selected. Which can be done with: app.executeCommand(app.findMenuCommandId("Select All"));
However, the cursor must be in the field for that to work.
I'm trying to place the cursor in a textlayer text field with Extendscript in After Effects. I can't see anyway to do that.
2)
I can create an external file from Extendscript like this:
Code: Select all
//This works on Vista and Win 7, XP requires the user to copy 'clip.exe' to the 'sys32' folder.
function copyTextToClipboard2(text)
{
var folderForTempFiles = Folder.temp.fsName;
//alert(folderForTempFiles)
// create a new textfile and put the text into it
var clipTxtFile =new File(folderForTempFiles + "/ClipBoard.txt");
clipTxtFile.open('w');
clipTxtFile.write(text);
clipTxtFile.close();
// use the clip.exe to copy the contents of the textfile to the windows clipboard
var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat");
clipBatFile.open('w');
clipBatFile.writeln("clip < " + folderForTempFiles + "/ClipBoard.txt");
clipBatFile.close();
clipBatFile.execute();
}
I could test for which OS people are on and then use the correct function.
Does anyone have an apple script version of the above function that could be executed from within Extendscript?