edited 2024-04-03



// check fonts in group of name;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var theStuff = [["sfx", "Arial Narrow", "Regular"], ["speech", "Myriad Pro", "Regular"]];
var theResults = new Array;
// check groups;
for (var n = 0; n < theStuff.length; n++) {
var theLayers = collectTypeLayersInGroupOfName (theStuff[n][0]);
var theFont = theStuff[n][1];
var theStyle = theStuff[n][2];
// check fonts;
for (var m = 0; m < theLayers.length; m++) {
var theCheck = true;
var theseFonts = theLayers[m][3];
for (var o = 0; o < theseFonts.length; o++) {
if (theseFonts[o][0] != theFont || theseFonts[o][1] != theStyle) {theCheck = false}
};
if (theCheck == false) {theResults.push(theLayers[m])}
};
};
// results;
if (theResults.length > 0) {
selectLayerByID(theResults[0][2], false)
for (var p = 1; p < theResults.length; p++) {selectLayerByID(theResults[p][2], true)};
alert ("the layers\n\n"+theResults.join("\n\n")+"\n\ncontain incorrect fonts.");
} else {alert ("no problem found")}
};
////////////////////////////////////
////// collect layers in group of name //////
function collectTypeLayersInGroupOfName (theName) {
var theGroup = collectLayersOfName (theName, true);
var theLayers = new Array;
for (var a = 0; a < theGroup.length; a++) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
var isTypeLayer = layerDesc.hasKey(stringIDToTypeID("textKey"));
var theParentId = layerDesc.getInteger(stringIDToTypeID('parentLayerID'));
// check group names;
var theCheck = false;
while (theParentId != -1 && theCheck == false) {
//if (Number(theParentId) == Number(theGroup[0][2])) {theCheck = true};
if (Number(theParentId) == Number(theGroup[a][2])) {theCheck = true};
var theParent = getLayerNameAndParentIdById (theParentId);
theParentId = theParent[3];
};
// if type layer collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true && isTypeLayer == true && theCheck == true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
var theFonts = new Array;
for (var x = 0; x < rangeList.count; x++) {
var thisOne = rangeList.getObjectValue(x);
var aFont = thisOne.getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontName'));
var aStyle = thisOne.getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontStyleName'));
var theFrom = thisOne.getInteger(stringIDToTypeID('from'));
var theTo = thisOne.getInteger(stringIDToTypeID('to'));
theFonts.push([aFont, aStyle, theFrom, theTo]);
};
theLayers.push([theName, theIndex, theID, theFonts])
};
}
catch (e) {};
};
};
return theLayers
};
////// collect layers //////
function collectLayersOfName (theString, isGroup) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theColor = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("color")));
if (layerSet == "layerSectionStart" && isGroup == true) {
if (theName == theString) {theLayers.push([theName, theIndex, theID, theColor])}
};
if (layerSet != "layerSectionStart" && isGroup == false) {
if (theName == theString) {theLayers.push([theName, theIndex, theID, theColor])}
};
};
}
catch (e) {};
};
return theLayers
};
////// get parentid //////
function getLayerNameAndParentIdById (theID) {
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID( "Lyr " ), theID);
var layerDesc = executeActionGet(ref);
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theParentId = layerDesc.getInteger(stringIDToTypeID('parentLayerID'));
return [theName, theIndex, theID, theParentId]
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){
try {
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
} catch (e) {}
};