• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How to get text (word) for a unwanted font in Photoshop Script

Explorer ,
Jan 18, 2024 Jan 18, 2024

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?

 

NewBeginner1_0-1705593610038.png

 

My Expect Output:  unwanted font: "Font Name"   text: "tempor" 

 

TOPICS
Actions and scripting

Views

291

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 1 Correct answer

Community Expert , Jan 19, 2024 Jan 19, 2024

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: 

Screenshot 2024-01-19 at 13.58.23.png

// 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
...

Votes

Translate

Translate
Adobe
LEGEND ,
Jan 18, 2024 Jan 18, 2024

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.

Votes

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 18, 2024 Jan 18, 2024

Copy link to clipboard

Copied

Font Name:  "Myriad Pro"

 

How to get text (word) for a specific font ("Myriad Pro"). in Photoshop scripts

Votes

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
Community Expert ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

 

Screenshot 2024-01-19 at 11.51.49.png

// 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"));
};
};

 

Votes

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 19, 2024 Jan 19, 2024

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)

 

 

 

Votes

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
Community Expert ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

quote

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

Votes

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
Community Expert ,
Jan 19, 2024 Jan 19, 2024

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: 

Screenshot 2024-01-19 at 13.58.23.png

// 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"));
};
};

Votes

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 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

This is a useful script.

Thank you So much.

Votes

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
Community Expert ,
Jan 20, 2024 Jan 20, 2024

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«. 

Votes

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
LEGEND ,
Jan 20, 2024 Jan 20, 2024

Copy link to clipboard

Copied

You could modify this to get a list of all the fonts in a text layer.

Votes

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
Community Expert ,
Jan 21, 2024 Jan 21, 2024

Copy link to clipboard

Copied

LATEST

The first Script I posted does this. 

Votes

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