Last active
September 17, 2015 13:20
-
-
Save seutje/506d17d4003f6455bb44 to your computer and use it in GitHub Desktop.
Helper script to list all different fonts used in a specific Photoshop document. Do note that the PSD needs to be saved somewhere, a .csv file will be generated in the same folder listing all the font variants.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nicer_obj = function (obj) { | |
var new_obj = {} | |
for (key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
try { new_obj[key] = obj[key]; } catch (err) {} | |
} | |
} | |
return new_obj; | |
} | |
var seenIt = {}; | |
var progress = false; | |
function recurseLayers(docRef, nufile) { | |
var activeLayer; | |
if (docRef.layers && docRef.layers.length) { | |
for (var i = docRef.layers.length-1 ; i >=0 ; i--) { | |
// Set the active layer to the next layer in the loop. | |
if (progress) { | |
activeDocument.activeLayer = docRef.layers[i]; | |
} | |
activeLayer = docRef.layers[i]; | |
try { | |
if (activeLayer.kind == LayerKind.TEXT && | |
activeLayer.textItem && | |
activeLayer.textItem.contents && | |
activeLayer.textItem.font) { | |
if (app && | |
app.fonts && | |
app.fonts[activeLayer.textItem.font] && | |
app.fonts[activeLayer.textItem.font].name && | |
!seenIt[app.fonts[activeLayer.textItem.font].name]) { | |
seenIt[app.fonts[activeLayer.textItem.font].name] = true; | |
nufile.write( app.fonts[activeLayer.textItem.font].name +"," + app.fonts[activeLayer.textItem.font].postScriptName + "\n"); | |
} | |
} | |
} | |
catch (e) { | |
} | |
if (activeLayer.layers) { | |
recurseLayers(activeLayer, nufile); | |
} | |
} | |
} | |
} | |
if (documents.length > 0) { | |
progress = confirm("Would you like to see the active layer being inspected? (increases runtime significantly)"); | |
var fileName = prompt("Please specify a filename (.csv will be appended).", '') || activeDocument.name + " - Fonts Used"; | |
// Tell Photoshop not to display any dialogs. | |
//displayDialogs = DialogModes.NO; | |
// Create a reference to the active document. | |
var docRef = activeDocument; | |
CurrentFolder = activeDocument.path; | |
// Loop through the layers one at a time. docRef.layers.length contains the number of | |
// layers including the background. | |
//Create the Excel comma delimited file in the current folder | |
var nufile = new File(CurrentFolder + "/" + fileName + '.csv' ); | |
nufile.open("w"); | |
nufile.write("Font Name,Font Post Script Name" + "\n"); | |
recurseLayers(docRef, nufile); | |
//Close the Excel comma delimited file | |
nufile.close(); | |
alert("Finished, stored in: " + CurrentFolder + "/" + fileName + ".csv"); | |
} | |
else { | |
// Gives this message if you don't have a document open in Photoshop. | |
alert("You must have at least one open document to run this script! "); | |
} | |
// Set the objects to nothing to release to the system. | |
docRef = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment