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.
You need to work with text styles in ActionManager. For example, a similar task was discussed here: Superscript text font change using script
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
...
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
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())
Copy link to clipboard
Copied
jazz-y and r-bin,
This is perfect! Thank you I really appreciate it!