Adobe Photoshop CS2 – Applying color to a text item

In this section, we will add a layer to the HelloWorldDoc script, then change the layer to a text object that displays the text Hello, World! in red.

Before you begin, do the following:

  • Quit Adobe Photoshop CS2.
  • Open the script file HelloWorldDoc in your script editor application.

To create and specify details in a text item:

  1. Type the following code into the HelloWorldDoc script immediately before the commented statements that restore original preferences.
    //create a reference to the active document
    docRef = app.activeDocument
    
    //create a variable named textColor
    //create a SolidColor object whose color is red
    //assign the object to textColor
    textColor = new SolidColor
    textColor.rgb.red = 255
    textColor.rgb.green = 0
    textColor.rgb.blue = 0
    
    helloWorldText = "Hello, World!"
    
    //create a variable named newTextLayer
    //use the add() method of the artLayers class to create a
    //layer object assign the object to newTextLayer
    newTextLayer = docRef.artLayers.add()
    
    //use the kind property of the artLayer class to make the
    //layer a text layer
    newTextLayer.kind = LayerKind.TEXT
    
    newTextLayer.textItem.contents = helloWorldText
    newTextLayer.textItem.position = Array(0.75, 1)
    newTextLayer.textItem.size = 36
    newTextLayer.textItem.color = textColor
    
  2. Save the script, and then open Adobe Photoshop CS2 and select the script from the Scripts menu (choose File > Script > HelloWorldDoc). Be patient while Adobe Photoshop CS2 executes your commands one by one.
  3. After viewing the document in Adobe Photoshop CS2, close Adobe Photoshop CS2 without saving the document.