Skip to content

Instantly share code, notes, and snippets.

@davestewart
Created May 23, 2013 13:51
Show Gist options
  • Save davestewart/5636216 to your computer and use it in GitHub Desktop.
Save davestewart/5636216 to your computer and use it in GitHub Desktop.
PhotoShop Script to check the consistency of fonts in a document
/**
* PhotoShop Script to check the consistency of fonts in a document
* @author Dave Stewart
* @date 23 May 2013
* @url twitter.com/dave_stewart
*/
function checkFonts(fontName)
{
// functions
function checkSet(set)
{
for(var j = 0; j < set.layers.length; j++)
{
layer = set.layers[j];
if(layer.kind == LayerKind.TEXT)
{
count ++;
font = layer.textItem.font;
if(font.indexOf(fontName) == -1)
{
str += (set instanceof Document ? '' : set.name + '/') + layer.name + ' : ' + font + '\n';
}
}
}
}
// variables
var str = '';
var set, layer, font;
var sets = app.activeDocument.layerSets;
var count = 0;
// check layers
checkSet(app.activeDocument);
// check sets
for(var i = 0; i < sets.length; i++)
{
checkSet(sets[i]);
}
// alert
if(count == 0)
{
alert('No text layers in document');
}
else if(str)
{
alert('The following layers are using a font other than ' + fontName + ':\n\n' + str);
}
else
{
alert('All fonts OK!');
}
return str;
}
var fontName = prompt('Check all text layers for the usage of font:', 'Lato');
if(fontName)
{
checkFonts(fontName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment