Copy link to clipboard
Copied
Hi,
I'm working with scripts that get unwanted font text in PSDs. In some cases, there are text items with more than one font, so how to get a specific word?
My Expect Output: unwanted font: "Font Name" text: "tempor"
So modify the Script.
You can check for the specific font-name with an if-clause within the for-clause (edited) and use the »from« and »to«-values to determine the affected letters.
Edit:
// based on code by michael l hale;
// get letters with specific fonts from selected type layer;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
if (app.activeDocument.activeLayer.kind == LayerKind.TEXT) {
var theFont = "Arial Black";
var ref = new ActionReference();
ref.putEnumerated( c
...
Copy link to clipboard
Copied
How do you determine which font is "unwanted"? There is not a way in the DOM to do this, you'd need Action Manager code.
Copy link to clipboard
Copied
Font Name: "Myriad Pro"
How to get text (word) for a specific font ("Myriad Pro"). in Photoshop scripts
Copy link to clipboard
Copied
// based on code by michael l hale;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
if (app.activeDocument.activeLayer.kind == LayerKind.TEXT) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var paragraphStyle = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));
var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
var theFonts = new Array;
for (var m = 0; m < rangeList.count; m++) {
var thisOne = rangeList.getObjectValue(m);
var aFont = thisOne.getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
var theFrom = thisOne.getInteger(stringIDToTypeID('from'));
var theTo = thisOne.getInteger(stringIDToTypeID('to'));
theFonts.push([aFont, theFrom, theTo]);
};
alert ("\n"+theFonts.join("\n"));
};
};
Copy link to clipboard
Copied
Super, thank you
But I need any one font text.
Please provide the script for the "KoHo-Regular" font match text (content)
Copy link to clipboard
Copied
Please provide the script for the "KoHo-Regular" font match text (content)
By @New Beginner1
Scripts aren't "provided" unless indicated. They are written by our volunteer scripters.
Jane
Copy link to clipboard
Copied
So modify the Script.
You can check for the specific font-name with an if-clause within the for-clause (edited) and use the »from« and »to«-values to determine the affected letters.
Edit:
// based on code by michael l hale;
// get letters with specific fonts from selected type layer;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
if (app.activeDocument.activeLayer.kind == LayerKind.TEXT) {
var theFont = "Arial Black";
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var theText = textDesc.getString(stringIDToTypeID('textKey'));
var paragraphStyle = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));
var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
var theFonts = new Array;
for (var m = 0; m < rangeList.count; m++) {
var thisOne = rangeList.getObjectValue(m);
var aFont = thisOne.getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
var aFontName = thisOne.getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontName'));
var theFrom = thisOne.getInteger(stringIDToTypeID('from'));
var theTo = thisOne.getInteger(stringIDToTypeID('to'));
if (aFontName == theFont) {theFonts.push([aFontName, theText.slice(theFrom, theTo), theFrom, theTo]);}
};
alert ("\n"+theFonts.join("\n"));
};
};
Copy link to clipboard
Copied
This is a useful script.
Thank you So much.
Copy link to clipboard
Copied
I am not ruling out that someone else may provide a better Script but if this one does what you need please mark the post as »Correct Answer«.
Copy link to clipboard
Copied
You could modify this to get a list of all the fonts in a text layer.
Copy link to clipboard
Copied
The first Script I posted does this.