[ExtendScript] Cannot set TextRange.justification to value in ParagraphStyle
We cannot successfully set textFrame.textRange.justification to the value in the applied ParagraphStyle.
For example, if the text has [Normal Paragraph Style] applied, which for me has Justification.LEFT, then I cannot set that text to have Justification.LEFT in cases where the justification has been changed.
(Tested on MacOS 15.4.1 Adobe Illustrator 29.5.1, but this appears to be an old bug.)
Steps to reproduce:
1. Create new document
2. Run the below script
Expected Result: all tests passed and no alert message appears.
Actual result: Failed to set textRange.justification to LEFT.
Script:
(function () {
var doc = app.activeDocument,
textFrame = doc.textFrames.add();
textFrame.textRange.contents = 'Hello.';
// prepare for the test, ensuring - due to the bug - that the justification won't match the applied paragraph style
textFrame.textRange.justification = Justification.RIGHT;
textFrame.textRange.justification = Justification.CENTER;
textFrame.textRange.justification = Justification.LEFT;
// test RIGHT justification
textFrame.textRange.justification = Justification.RIGHT;
if (textFrame.textRange.justification !== Justification.RIGHT)
alert('Failed to set textRange.justification to RIGHT.');
// test CENTER justification
textFrame.textRange.justification = Justification.CENTER;
if (textFrame.textRange.justification !== Justification.CENTER)
alert('Failed to set textRange.justification to CENTER.');
// test LEFT justification
textFrame.textRange.justification = Justification.LEFT;
if (textFrame.textRange.justification !== Justification.LEFT)
alert('Failed to set textRange.justification to LEFT.');
})();
Additional note: in the link above, users discovered that performing a resize on the textFrame somehow removes the blockage and Justification.LEFT can be set afterwards. Perhaps it breaks the link to the paragraph style?
Edit 2025-05-23: to add details about the possible link to the applied paragraph style.
A possible temporary workaround:
// set LEFT justification
textFrame.textRange.justification = Justification.LEFT;
// now check it
if (
Justification.LEFT !== textFrame.textRange.justification
&& Justification.LEFT === textFrame.textRange.paragraphStyles[0].justification
) {
// bypass a bug where we can't set the attribute that matches the applied paragraph style:
// - change the applied paragraph style's justification
// - then change the textFrame's justification to the style's previous value,
// - then return the paragraph styles original setting
textFrame.textRange.paragraphStyles[0].justification = Justification.CENTER;
textFrame.textRange.justification = Justification.LEFT;
textFrame.textRange.paragraphStyles[0].justification = Justification.LEFT;
}

-
m1b commented