Skip to content

Instantly share code, notes, and snippets.

@marcus-downing
Created May 23, 2012 22:43
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcus-downing/2778294 to your computer and use it in GitHub Desktop.
Save marcus-downing/2778294 to your computer and use it in GitHub Desktop.
List the fonts used in all the Illustrator files in a folder
/*
List the fonts
This shows you all the fonts used in all the Illustrator files in a folder,
even if the fonts aren't installed on your system.
You can then replace them with this script: https://gist.github.com/2778305
*/
function getAllFiles(folder) {
var fileList = [];
function recurse (folder) {
var files = folder.getFiles("*.ai");
for (var i = 0; i < files.length; i++)
fileList.push(files[i]);
var folders = folder.getFiles();
var len = folders.length;
for (var i = 0; i < len; i++) {
if (folders[i] instanceof Folder) {
recurse(folders[i]);
}
}
}
if (folder != null)
recurse(folder);
return fileList;
}
// collect the fonts
var sourceFolder = Folder.myDocuments.selectDlg( 'Select the folder with Illustrator files in which you want to replace fonts');
var files = getAllFiles(sourceFolder);
var fonts = [];
for ( var i = 0; i < files.length; i++ ) {
var doc = app.open(files[i]);
var frames = doc.textFrames;
for ( var j = 0; j < frames.length; j++ ) {
var ranges = frames[j].textRanges;
range_loop:
for ( var k = 0; k < ranges.length; k++ ) {
var range = ranges[k];
var family = range.characterAttributes.textFont.family;
var style = range.characterAttributes.textFont.style;
var entry = { 'family': family, 'style': style };
var elen = fonts.length;
for (var e = 0; e < elen; e++) {
var dentry = fonts[e];
if (entry.family == dentry.family && entry.style == dentry.style)
continue range_loop;
}
fonts.push(entry);
}
}
doc.close();
}
// Adapted from the Illustrator Scripting Reference CS5 page 216
// Creates a new A3 sized document and display a list of available fonts until the document is full.
var edgeSpacing = 10;
var columnSpacing = 230;
var docPreset = new DocumentPreset;
docPreset.width = 1191.0;
docPreset.height = 842.0
var doc = documents.addDocument(DocumentColorSpace.CMYK, docPreset);
var labelRef = doc.textFrames.add();
if (labelRef) {
labelRef.textRange.characterAttributes.size = 10;
labelRef.contents = "Fonts used in "+sourceFolder.fullName;
labelRef.top = doc.height - edgeSpacing;
labelRef.left = edgeSpacing;
}
var fontName = "";
var x = edgeSpacing;
var y = (doc.height - edgeSpacing - 20);
var count = fonts.length;
for (var i = 0; i < count; i++) {
//sFontName = ;
//sFontName += " / ";
fontName = fonts[i].family + " / " + fonts[i].style;
var textRef = doc.textFrames.add();
textRef.textRange.characterAttributes.size = 10;
textRef.contents = fontName;
textRef.top = y;
textRef.left = x;
// check wether the text frame will go off the edge of the document
if ((x + textRef.width)> doc.width){
textRef.remove();
iCount = i;
break;
} else{
// display text frame
if( (y-=(textRef.height)) <= 20 ) {
y = (doc.height - edgeSpacing - 20);
x += columnSpacing;
}
}
}
redraw();
@marc99dr
Copy link

Hi there
I'm not a node expert but I would need to identify all fonts used by Illustrator files in a (lot of) folders.
I tried to install node using yum on linux. But executing "node list_used_fonts.jsx" gives me an error because the object Folder line 29 is not defined:

var sourceFolder = Folder.myDocuments.selectDlg( 'Select the folder with Illustrator files in which you want to replace fonts');

Could point me to the right direction?
Thanks!

@marcus-downing
Copy link
Author

Hi,
The version of JavaScript (or ExtendScript) used by Adobe Illustrator is very different from the dialect you'll find anywhere else. It needs to be run directly inside Illustrator to get the APIs it needs.

image

That should then come up with some dialog boxes prompting you to pick a folder.

@marcus-downing
Copy link
Author

You may have more success with this version of the script:

https://github.com/dyslexic-charactersheets/scripts/blob/master/List%20used%20fonts%20to%20CSV.jsx

It relies on the Tools.jsxinc and underscore.js files, so download those together.

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