Copy link to clipboard
Copied
I want to copy a string variable to Windows clipboard. How can I do that in extendScript?
It would be better if you can tell me to do the same for MacOS in addition.
Thanks In Advance.
1 Correct answer
There you go. Works for Win and OSx:
function copyToClipboard(string) {
var cmd, isWindows;
string = (typeof string === 'string') ? string : string.toString();
isWindows = $.os.indexOf('Windows') !== -1;
cmd = 'echo "' + string + '" | pbcopy';
if (isWindows) {
cmd = 'cmd.exe /c cmd.exe /c "echo ' + string + ' | clip"';
}
system.callSystem(cmd);
}
Copy link to clipboard
Copied
You have to call the respective menu commands of the apps.
Mylenium
Copy link to clipboard
Copied
No. I wasn't talking about Copy Menu Command.. I'm talking about copy to clipboard function in Extendscript itself. Like say we have a edittext and a button. whenever I press the button. The text in editttext should be copied to clipboard. How can I achieve that?
Copy link to clipboard
Copied
There is no such thing. A clipboard is a system-level mechanism that involves managing memory addresses and such, none of which a script can do. You have to use the host program's features and implement respective stuff. The only other option would be to create your own temporary files and manipulate it, but this will inevitably cause issues if users don't have the respective preferences enabled and security tools interfere.
Mylenium
Copy link to clipboard
Copied
There you go. Works for Win and OSx:
function copyToClipboard(string) {
var cmd, isWindows;
string = (typeof string === 'string') ? string : string.toString();
isWindows = $.os.indexOf('Windows') !== -1;
cmd = 'echo "' + string + '" | pbcopy';
if (isWindows) {
cmd = 'cmd.exe /c cmd.exe /c "echo ' + string + ' | clip"';
}
system.callSystem(cmd);
}
Copy link to clipboard
Copied
Thank you so much.
That works great....!! Only thing I've to modify is in the cmd variable. I need to remove the space in
' | clip"';
//into
'| clip"';
to avoid additional space in the actual String value.
Copy link to clipboard
Copied
thanks..
Copy link to clipboard
Copied
Hi Tomas
This is nice and works very good, thanks for that.
But for me it works only with non-linebreaked strings.
"test\rtest" outputs "testtest"
"test\ntest" doesn´t change the clipboard at all.
I want to copy the position value of a layer to the clipboard, but to paste it correctly it has to be in this format:
Adobe After Effects 8.0 Keyframe Data
Units Per Second 30
...
...
And I think because this is several lines it doesn´t work with your script.
Do you have idea how to correct that, or even better, how to copy the position value of a layer directly to the clipboard?
Thanks so much
Copy link to clipboard
Copied
This is working nice in AE but not in AI. Do you know why by any chance?
Copy link to clipboard
Copied
How do you do the opposite? Get the clipboard from the system? Trying to do it for ages

