Skip to content

Instantly share code, notes, and snippets.

@gneutzling
Last active November 8, 2016 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gneutzling/24df7acf2984bdaf5248 to your computer and use it in GitHub Desktop.
Save gneutzling/24df7acf2984bdaf5248 to your computer and use it in GitHub Desktop.
Show fonts used in a Photoshop file.
// Salvar o script dentro de Photoshop > Presets > Scripts
// http://superuser.com/questions/268785/find-all-the-fonts-used-in-a-photoshop-file
var p = new ActionReference();
function arrayUnique(a){
var t = []
i = a.length;
while(i--) {
var f = false,
n = t.length;
while (n--) {
if(a[i] === t[n]) {
f = true;
}
}
if(!f) {
t.push(a[i]);
}
}
return t;
}
function findFonts() {
p.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var c = executeActionGet(p).getInteger(charIDToTypeID('NmbL'))+1,
fonts = [];
while(c--) {
var r = new ActionReference(),
descLayer,
layerStyles,
countStyles;
r.putIndex( charIDToTypeID( 'Lyr ' ), c );
try {
descLayer = executeActionGet(r);
} catch (e) {
continue;
}
if(!descLayer.hasKey(stringIDToTypeID( 'textKey' ))) continue;
layerStyles = descLayer.getObjectValue(stringIDToTypeID('textKey')).getList(stringIDToTypeID('textStyleRange'));
countStyles = layerStyles.count;
while(countStyles--) {
var n = layerStyles.getObjectValue(countStyles).getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
fonts.push(n);
}
}
return arrayUnique(fonts).sort();
}
if (documents.length) {
var d = findFonts();
alert(d.length +' fonts f \n'+d.join('\n'));
} else {
alert('No fonts used in the active document.',);
}
@dcondrey
Copy link

dcondrey commented Nov 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment