• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How Can I Copy String in a variable to clipboard in extendScript?

Contributor ,
Feb 17, 2020 Feb 17, 2020

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.

TOPICS
How to , Resources , Scripting

Views

3.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Feb 19, 2020 Feb 19, 2020

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);
}

Votes

Translate

Translate
LEGEND ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

You have to call the respective menu commands of the apps.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 18, 2020 Feb 18, 2020

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2020 Feb 18, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 19, 2020 Feb 19, 2020

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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 19, 2020 Feb 19, 2020

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 12, 2020 Jun 12, 2020

Copy link to clipboard

Copied

thanks..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 12, 2020 Jun 12, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 31, 2022 Dec 31, 2022

Copy link to clipboard

Copied

This is working nice in AE but not in AI. Do you know why by any chance?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2023 May 29, 2023

Copy link to clipboard

Copied

LATEST

How do you do the opposite? Get the clipboard from the system? Trying to do it for ages

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines