• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Collect used document fonts and export them to folder

Participant ,
Jul 11, 2018 Jul 11, 2018

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

TOPICS
Scripting

Views

441

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 11, 2018 Jul 11, 2018

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

Votes

Translate

Translate
Community Expert ,
Jul 11, 2018 Jul 11, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 11, 2018 Jul 11, 2018

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2018 Jul 11, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

LATEST

Thank you so much! This looks a lot cleaner and more readable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines