Copy link to clipboard
Copied
Hello all!
I am needing a little bit of help with a script I am using to collect a
documents fonts. It is all working fine, except I don't like how it is
naming the folder it creates. I want the folder name to be simply "Document
fonts" and not include the InDesign file name. I would like the folder to be
in the same directory as the Indesign file. Would somebody be so kind as to
show me what I need to change in my code? I have the code I am using below.
If anything isn't clear enough, let me know.
var
myFonts = app.documents[0].fonts.everyItem().getElements(),
myDocument = app.activeDocument,
len = myFonts.length,
cFile, cName, outFile, i,
movefolder = myDocument.fullName + "Document fonts"
movefolder = Folder(movefolder);
if (!movefolder.exists) movefolder.create();
for(i=0;i<len;i++) {
cFile = File(myFonts.location);
if(!cFile.exists) continue;
cName = cFile.name;
outFile = File(movefolder + "/"+ cName);
cFile.copy(outFile);
}
Thanks in advance for your help!
Awitmer
Hi,
replace this:
cFile, cName, outFile, i,
movefolder = myDocument.fullName + "Document fonts"
movefolder = Folder(movefolder);
if (!movefolder.exists) movefolder.create();
with that:
cFile, cName, outFile, i ;
var movefolder = File( myDocument.fullName).parent+"/"+ "Document fonts" ;
movefolder = Folder( movefolder );
if (!movefolder.exists) movefolder.create();
Regards,
Uwe
Copy link to clipboard
Copied
Hi,
replace this:
cFile, cName, outFile, i,
movefolder = myDocument.fullName + "Document fonts"
movefolder = Folder(movefolder);
if (!movefolder.exists) movefolder.create();
with that:
cFile, cName, outFile, i ;
var movefolder = File( myDocument.fullName).parent+"/"+ "Document fonts" ;
movefolder = Folder( movefolder );
if (!movefolder.exists) movefolder.create();
Regards,
Uwe
Copy link to clipboard
Copied
Thank you soo much! You made my day! It is working great now! I will mark your answer as correct.
Copy link to clipboard
Copied
And you could check if the active document was ever saved.
If not, exit, because there is no fullName of the document.
if(app.documents.length == 0){ exit() };
if(!app.documents[0].saved){ exit() };
Put both lines at the beginning of your script.
However, it would be better to wrap all the code into a self-executing anonymous function like below.
Simply use return instead of exit() inside this function.
( function()
{
// No document open:
if(app.documents.length == 0){ return };
// Document was never saved:
if(!app.documents[0].saved){ return };
var myDocument = app.activeDocument;
var myFonts = myDocument.fonts.everyItem().getElements();
var len = myFonts.length;
var cFile, cName, outFile, i ;
var movefolder = File( myDocument.fullName).parent+"/"+ "Document fonts" ;
movefolder = Folder( movefolder );
if (!movefolder.exists){ movefolder.create() };
for(i=0;i<len;i++)
{
cFile = File( myFonts.location );
if( !cFile.exists ){ continue } ;
cName = cFile.name;
outFile = File(movefolder + "/"+ cName);
cFile.copy(outFile);
}
}() )
Regards,
Uwe
Copy link to clipboard
Copied
Thank you so much! This looks a lot cleaner and more readable.