Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Photoshop Scripting - textItem Properties

Explorer ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

I'm looking for a way to get the text properties of each character of a Photoshop text layer.

The Photoshop scripting guide doesn't show how to gain access to substring properties of a text layer.

 

For example:

 

Given a Photoshop document with a text layer named "TEXT" that contains the text "Hello World!" where "Hello" is set with the font of Helvetica Bold and "World!" is set with the font of Futura.

 

When you run the following script it returns "Helvetica-Bold"

 

 

alert(app.activeDocument.layers.getByName("TEXT").textItem.font);

 

 

How do you gain access to the text properties of "World!"

It seems that all properties returned of a textItem are based on the first character of the textItem contents.

TOPICS
Actions and scripting

Views

508

Likes

Translate

Translate

Report

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 2 Correct answers

Adobe Community Professional , Jan 22, 2021 Jan 22, 2021
You need to work with text styles in ActionManager. For example, a similar task was discussed here: Superscript text font change using script

Likes

Translate

Translate
Adobe Community Professional , Jan 22, 2021 Jan 22, 2021
Try this method var r = new ActionReference(); var d = new ActionDescriptor(); r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json")); r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); d.putReference(stringIDToTypeID("null"), r); d.putBoolean(stringIDToTypeID("includeAncestors"), false); d.putBoolean(stringIDToTypeID("getTextStyles"), true) d.putBoolean(stringIDToTypeID("selectedLayers"), true); eval("var json="+exe...

Likes

Translate

Translate
Adobe Community Professional ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

You need to work with text styles in ActionManager. For example, a similar task was discussed here: Superscript text font change using script

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Try this method

 

 

var r = new ActionReference();
var d = new ActionDescriptor();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);

d.putBoolean(stringIDToTypeID("includeAncestors"), false);
d.putBoolean(stringIDToTypeID("getTextStyles"), true)

d.putBoolean(stringIDToTypeID("selectedLayers"), true);

eval("var json="+executeAction(stringIDToTypeID("get"), d, DialogModes.NO).getString(stringIDToTypeID("json")));

alert(json.toSource())

 

Likes

Translate

Translate

Report

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

LATEST

jazz-y and r-bin,

 

This is perfect! Thank you I really appreciate it!

Likes

Translate

Translate

Report

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