Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Photoshop JSX -- How do I copy arbitrary text to the clipboard?

Right now I am using the prompt command as a workaround to copy arbitrary text out of my JSX script in Photoshop.

prompt("to copy",(horizontalcenter.toString()) + ", " + verticalcenter.toString());

And that is giving me the information that I want. The "to copy" just gives the title, then the information I want to copy out of Photoshop is in the prompt box already selected. So all I have to do is hit control C, go to Notepad++ where I need this information, and hit control V.

It works, but it could be faster. There has to be a way to copy this information out of Photoshop straight to the clipboard, no?

like image 689
Lars Markelson Avatar asked Nov 01 '10 01:11

Lars Markelson


1 Answers

Photoshop 13.1 (the latest Creative Cloud release of Photoshop CS6) now has a hook allowing you to do this directly. Here's a sample function:

function copyTextToClipboard( txt )
{
    const keyTextData         = app.charIDToTypeID('TxtD');
    const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );

    var textStrDesc = new ActionDescriptor();

    textStrDesc.putString( keyTextData, txt );
    executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );
}

Please note this won't work in versions of Photoshop prior to 13.1

like image 194
J. Peterson Avatar answered Oct 15 '22 09:10

J. Peterson