Skip to main content
Known Participant
November 16, 2023
Question

fontStyleName property unavailable for font

  • November 16, 2023
  • 5 replies
  • 1371 views

I have a script that goes through an open InDesign document and creates a report with information on the fonts in the document.

 

Occasionally, I receive an error string:  "The requested scripting property is not available for the font." despite all fonts being loaded/installed in the InDesign document.

 

The missing property is the fontStyleName. Could this be caused by a font conflict? Even if that were the case, wouldn't the script be using the font property of the font that is installed?

 

This topic has been closed for replies.

5 replies

TᴀW
Legend
November 17, 2023

Something like this should work, without try-catch:

 

allFonts = document.fonts.everyItem().properties;
s = "Font Name\tStyle\tLocation\tStatus\r"
for (i = 0; i < allFonts.length; i++){
	s += allFonts[i].name.split("\t")[0] + "\t" + allFonts[i].fontStyleName + "\t" + allFonts[i].location +  "\t" + allFonts[i].status.toString() + "\r"
};
alert(s);

... the reason being that you get an array of objects, with each object containing all the properties of each font. If a certain property doesn't exist for the font, accessing it via the object will return undefined, as for any property not contained in an object, as opposed to trying to access it from the font object itself, in which case InDesign scripting will throw an error.

 

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
m1b
Community Expert
Community Expert
November 17, 2023

Excellent idea @TᴀW!

rob day
Community Expert
Community Expert
November 17, 2023

Hi @michaelr26894937 , I’m not sure the code has to be that complicated. Something like this:

 

 

 

 

var path = Folder.desktop + "/Font Info.csv";
var f = app.activeDocument.fonts;
var fi = "Font Name\tStyle\tLocation\tStatus\r"

for (var i = 0; i < f.length; i++){
    fi += f[i].name.split("\t")[0] + "\t" + f[i].fontStyleName + "\t" + f[i].location +  "\t" + f[i].status.toString() + "\r"
};

writeCSV(path,fi)

/**
* Write CSV 
* @ param the file path 
* @ param the text 
* 
*/
function writeCSV(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}

 

 

 

 

Outputs this CSV:

For this doc:

 

leo.r
Community Expert
Community Expert
November 17, 2023

@rob day :

 

I only think he'll get the very same error for some fonts that was the reason for his post here:

 

+ f[i].fontStyleName

 

So he may need to try-catch this property (as well as location) first?

rob day
Community Expert
Community Expert
November 17, 2023

So he may need to try-catch this property (as well as location) first?

 

Yes.

Another option might be with the name property. With my font library and Adobe type fonts, the name string always includes the name and style with a tab in between. So in my code this returns the name without the style :

f[i].name.split("\t")[0]

and this would return just the style

f[i].name.split("\t")[1]

 

 

 

Robert at ID-Tasker
Legend
November 16, 2023

Can you show us your script? I'm pretty sure it would be just a case of adding try...catch.

 

Known Participant
November 16, 2023
Here is the part of the script that collects the font information. Thanks.
 
(function () {
var doc = app.activeDocument;
var myBaseName = doc.name;
var familyNames = [];
var i;
var names = [];
var styleNames = [];
var fontTypes = [];
var fileNames = [];
var missingFonts = false;

if (/InDesign/.test(app.name)) {
familyNames = app.activeDocument.fonts.everyItem().fontFamily;
styleNames = app.activeDocument.fonts.everyItem().fontStyleName;
fontNames = app.activeDocument.fonts.everyItem().name;
fontTypes = app.activeDocument.fonts.everyItem().fontType;
fileNames = app.activeDocument.fonts.everyItem().location;

for (i = 0; i < fontNames.length; i++) {
var file = new File(fileNames[i]);
var fileName = decodeURI(file.name);
names.push([familyNames[i] + " " + styleNames[i], fileName, fontTypes[i]]);

var fontStatus = app.activeDocument.fonts.everyItem().status.toString();

if (( fontStatus.indexOf("NOT_AVAILABLE ") !== -1) || ( fontStatus.indexOf("SUBSTITUTED") !== -1 ))
 
{
 
alert ("Document appears to have missing fonts");
 
exit();
 
}

}

if (!missingFonts) {
writeCsv("InDesign Document", names);
} else {
alert("One or more fonts are missing. Please check and try again.");
}
}
Robert at ID-Tasker
Legend
November 16, 2023

Unfortunately, your code won't work after adding try....catch - it needs to be re-written - but I'm not JS guy.

 

In your code, author assumed that this part:

familyNames = app.activeDocument.fonts.everyItem().fontFamily;
styleNames = app.activeDocument.fonts.everyItem().fontStyleName;
fontNames = app.activeDocument.fonts.everyItem().name;
fontTypes = app.activeDocument.fonts.everyItem().fontType;
fileNames = app.activeDocument.fonts.everyItem().location;

will always work and each array will have the same number of "records" - but if we start ignoring errors - there will be a different number of "records" and you'll get wrong sets of data.

 

I'm pretty sure @Peter Kahrel or @rob day or @brian_p_dts can re-write it for you.

 

Peter Kahrel
Community Expert
Community Expert
November 16, 2023

Those TTF/OTF mixes are always a problem.

 

Forgot to ask earlier: in "The requested scripting property is not available for the font", what is that property?

Known Participant
November 16, 2023
fontStyleName
Peter Kahrel
Community Expert
Community Expert
November 16, 2023

Which fornt (and font family) is that?

Known Participant
November 16, 2023

The designer used Gill Sans. I try to avoid this font if possible but it's not my Document. I noticed that there is a mixture of ttc and otf in their packaged Document fonts folder.

 

from the Indesign file: