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

Is it possible to paste the copy content to the text item via script?

Participant ,
Nov 05, 2014 Nov 05, 2014

Hi All,

I am looking into the solution of pasting the copied content (by cntrl + c) to the text item.

Following is my scenario,

- Have the text (copied from cntrl + c).

- Now I want to create a text item on the current doc.

- Paste the content to that text item. ( Looking script for this step).

How can we accomplish this?

Thanks for any help.

TOPICS
Actions and scripting
1.3K
Translate
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

Participant , Nov 06, 2014 Nov 06, 2014

There is no problem to get/set the content of text layer. But here I want to get the content (copied from CNTRL+C command from notepad) present in the memory and set it to the text item.

I guess it's a little confussing. Let me put this in another way,

- Create a shape layer and select it

- Execute the following script,

var idcopyLayerCSS = stringIDToTypeID( "copyLayerCSS" );

    var desc111 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref31 = new ActionReferenc

...
Translate
Adobe
Engaged ,
Nov 06, 2014 Nov 06, 2014

Don't know about Photoshop, but InDesign has app.paste(). This creates a text item in the active doc and pastes the content from clipboard.

I guess there should be a similar method in the PS APIs.

Translate
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
Participant ,
Nov 06, 2014 Nov 06, 2014

Yes, there is an API in Ps,

app.activeDocument.paste()

But it's not working here. I am getting exception every time "The command "Paste" is not currently available". I don't know why it behave like this.

Translate
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
Enthusiast ,
Nov 06, 2014 Nov 06, 2014

If the layer is a text layer, you can use layer.textItem.contents to get & set the text. Before setting you might have to sanitize line changes like my_text = my_text.replace(/\r\n/g, "\\r").replace(/\n/g, "\\r")

Translate
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
Participant ,
Nov 06, 2014 Nov 06, 2014

There is no problem to get/set the content of text layer. But here I want to get the content (copied from CNTRL+C command from notepad) present in the memory and set it to the text item.

I guess it's a little confussing. Let me put this in another way,

- Create a shape layer and select it

- Execute the following script,

var idcopyLayerCSS = stringIDToTypeID( "copyLayerCSS" );

    var desc111 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref31 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref31.putEnumerated( idLyr, idOrdn, idTrgt );

    desc111.putReference( idnull, ref31 );

executeAction( idcopyLayerCSS, desc111, DialogModes.NO );

After executing the script, the css data of the selected layer is stored in the memory.

Now my problem is to get the content of this css data.

How I am going to do this?

Translate
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
Enthusiast ,
Nov 07, 2014 Nov 07, 2014

Ok, now I get it Accessing clipboard directly is probably hard, at least I don't know a way.

Exceptions "not currently available" often mean "option in menu is disabled". A good reference is trying to do same through PS menus. In the case of having raw text (from apps like notepad) put text as ascii to clipboard and PS seems not to support it. If copy from Word you can actually paste because Word puts text and image and PS will paste the graphics as layer (i.e. you'd not get the text data).

I'd try creating a Javascrip dialog window with a text area and pasting there. You could even detect when it gets text and automatically close eliminating an OK-button.

Translate
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
Explorer ,
Dec 20, 2023 Dec 20, 2023

Having issues with formatting but here's a basic way if there's only one line of text. Edit directories accordingly. This is for windows OS: 

Make a Bat file "RunPowershell.bat":

@echo off
powershell -command "& {Get-Clipboard}" > "I:\output.txt"

Jsx file: 

// Function to execute a system command and capture its output
function executeCommand(command) {
  var fileObj = new File(command);
  fileObj.execute();
}

// Get clipboard data using the Batch script
var clipboardData = "";
try {
  executeCommand('I:\\RunPowershell.bat');
  
  // Read the output file
  var outputFile = new File('I:\\output.txt');
  outputFile.open('r');
  clipboardData = outputFile.read();
  outputFile.close();
  outputFile.remove();
} catch (e) {
  alert("Error executing Batch file: " + e);
}

// Create a new text layer in Photoshop
var textLayer = app.activeDocument.artLayers.add();
textLayer.kind = LayerKind.TEXT;
textLayer.textItem.contents = clipboardData;



Translate
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 Expert ,
Dec 20, 2023 Dec 20, 2023
LATEST
Translate
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