skip to Main Content

I am trying to write a script that will update the value of a text layer in Photoshop.

I have a layer stored in a variable myLayer which I log out so I know it is an ArtLayer with a type of LayerKind.TEXT and has a textItem object associated that has a string value in place. All as I would expect.

The documentation says that textItem.contents is read-write so I thought myLayer.textItem.contents = "Hello World" should update the value but when I try this I get General Photoshop Error occurred. This functionality might not be available in this version of Photoshop.

Can anyone advise on what I’m missing?

I am using Photoshop CC 2014 and the CC 2014 Javascript Reference

Thankyou in advance for you help 🙂

2

Answers


  1. Its hard to see whats going wrong when there is no code example. This works for me.

    Tested in PS CC 2014 Mac OSX

    // needs a Photoshop document with only one textlayer
    var d = app.activeDocument;
    var l = d.artLayers[0];
    if(l.hasOwnProperty ("textItem")){
        $.writeln("yes");
        l.textItem.contents = "Hello World";
    }
    
    Login or Signup to reply.
  2. This works in CS2: (Assuming the active layer (mylayer) is a text layer)

    var srcDoc = app.activeDocument;
    var myLayer= srcDoc.activeLayer;
    
    var text = myLayer.textItem.contents;
    myLayer.textItem.contents = "Hello World";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search