Skip to main content
Inspiring
July 31, 2023
Answered

Change left or right indent via script

  • July 31, 2023
  • 2 replies
  • 873 views

So this is a bit puzzling:

app.activeDocument.activeLayer.textItem.leftIndent = new UnitValue(10, 'pt');

Doesn't appear to do anything. Whereas something similar 

app.activeDocument.activeLayer.textItem.contents = "spoon";

changes the text layer's contents to "spoon".

 

So...how do you change the indent size with code??

This topic has been closed for replies.
Correct answer Stephen Marsh

I have now had time to test and get the same results.

 

The only success I had was to use AM code.

 

set(10);

function set(startIndent) {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("property"), s2t("paragraphStyle"));
    reference.putEnumerated(s2t("textLayer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor2.putInteger(s2t("textOverrideFeatureName"), 808464435);
    descriptor2.putUnitDouble(s2t("startIndent"), s2t("pixelsUnit"), startIndent);
    descriptor.putObject(s2t("to"), s2t("paragraphStyle"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
}

2 replies

Stephen Marsh
Stephen MarshCorrect answer
Community Expert
August 1, 2023

I have now had time to test and get the same results.

 

The only success I had was to use AM code.

 

set(10);

function set(startIndent) {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("property"), s2t("paragraphStyle"));
    reference.putEnumerated(s2t("textLayer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor2.putInteger(s2t("textOverrideFeatureName"), 808464435);
    descriptor2.putUnitDouble(s2t("startIndent"), s2t("pixelsUnit"), startIndent);
    descriptor.putObject(s2t("to"), s2t("paragraphStyle"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
}
Inspiring
August 1, 2023

Stephen,

Thank you, that works!

However, the bigger question remains: why doesn't the original code work. 

 

So mysterious...

 

 

Stephen Marsh
Community Expert
August 1, 2023

It must have worked at one time, who knows how long it's been broken?

Stephen Marsh
Community Expert
July 31, 2023

Where did you get .leftIndent from?

 

Edit: I found it - https://theiviaxx.github.io/photoshop-docs/Photoshop/TextItem/leftIndent.html#textitem-leftindent

 

Sometimes it's just better to enter the value without a unit of measure, then wrap the entire code or block in a unit of measure.

 

https://gist.github.com/MarshySwamp/898ae3237305787d0683125166aeb480

 

But I haven't had time to try...

Inspiring
July 31, 2023

I've already tried

var srcDoc = app.activeDocument;
var theLayer = srcDoc.activeLayer;
var left = new UnitValue(10, 'pt');
theLayer.textItem.leftIndent = left; // Does nothing
theLayer.textItem.contents = "spoon"; // Changes text
Brainiac
July 31, 2023

What shows

alert(activeDocument.activeLayer.textItem.leftIndent)

after operation?

I have everything working