4 Replies Latest reply on Jul 11, 2018 12:05 PM by Awitmer

    Collect used document fonts and export them to folder

    Awitmer Level 1

      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[i].location); 

       

        if(!cFile.exists) continue; 

       

        cName = cFile.name; 

       

        outFile = File(movefolder + "/"+ cName); 

       

        cFile.copy(outFile);    

       

        }  

       

       

       

       

       

      Thanks in advance for your help!

       

       

       

      Awitmer

       

       

       

       

        • 1. Re: Collect used document fonts and export them to folder
          Laubender Adobe Community Professional & MVP

          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

          • 2. Re: Collect used document fonts and export them to folder
            Awitmer Level 1

            Thank you soo much! You made my day! It is working great now! I will mark your answer as correct.

            • 3. Re: Collect used document fonts and export them to folder
              Laubender Adobe Community Professional & MVP

              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[i].location ); 
              
                      if( !cFile.exists ){ continue } ; 
                      cName = cFile.name; 
                      outFile = File(movefolder + "/"+ cName); 
                      cFile.copy(outFile);
                      
                  } 
              
              }() )
              

               

              Regards,
              Uwe

              • 4. Re: Collect used document fonts and export them to folder
                Awitmer Level 1

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