8 Replies Latest reply on Jan 10, 2012 9:24 AM by KuddRoww

    Batch Retrieve Image links

    KuddRoww Level 1

      Hi,

       

      I've found the File -> Package -> Report quite helpful for generating a detailed report for image links. However I am dealing with a few hundred files so the act of going into each one and generating a report individually is quite time consuming. I have been able to reduce the overall time by a) customing the hotkey for accessing the Package and b) memorizing the keystrokes required to complete each report however I can't help but think there has to be an easier way.

       

      My assumption is that there would be a way to script such a simple action so that I could simply hit play and have the file generated, am I correct?

       

      If not my second assumption is it would be easier to troll through the XML files and parse the links that way?

       

      Thank-you very much in advance for any and all support in this matter.

       

      Cheers,

       

      Kud

        • 1. Re: Batch Retrieve Image links
          absqua Level 4

          It looks like to me like the report generated with File=>Package=>Report is different, and much more detailed, than the "Instructions.txt" that results from actually packaging the document. I don't see a way to generate that more detailed report via script.

           

          What specific information do you need to have about the links? It shouldn't be too hard to generate a custom report.

           

          Jeff

          1 person found this helpful
          • 2. Re: Batch Retrieve Image links
            KuddRoww Level 1

            Hi Jeff,

             

            Firstly thank-you for your reply.

             

            To answer your question the fields in the report I am most interested are primarily related to the 'Links and Images' subsections of the report, specifically the link 'Status' and the 'Complete Name' of linked images.

             

            Until now I've simply need filtering the entire report using Excel which is a bloated process to say in the least. The ability to produce custom reports on Links and Images would be phenomenal.

             

            Thanks again,

             

            Kud

            • 3. Re: Batch Retrieve Image links
              absqua Level 4

              OK, try this out:

               

              var inFolder = Folder.selectDialog("Choose the folder that contains the InDesign documents.");
              if(inFolder === null){
                        exit();
              }
              var outFolder = Folder.selectDialog("Choose the folder to save the reports in.");
              if(outFolder === null){
                        exit();
              }
              
              var files = inFolder.getFiles("*.indd"),
                        fileStrings = [],
                        doc, i, l, link, j, k, reportFile;
              
              app.scriptPreferences.userInteractionLevel=UserInteractionLevels.NEVER_INTERACT;
              
              for(i = 0, l = files.length; i < l; i++) {
                        doc = app.open(files[i], false);
                
                        reportFile = File(outFolder + "/" + doc.name.replace(/\.indd$/,"") + ".csv");
                
                        fileStrings = ["\"link\",\"status\",\"complete name\""];
                
                        for(j = 0, k = doc.links.length; j < k; j++) {
                                  link = doc.links[j];
                                  fileStrings[fileStrings.length] = "\"" + link.name + "\",\"" + link.status.toString() + "\",\"" + link.filePath + "\"";
                        }
                        doc.close(SaveOptions.NO);
                
                        if(fileStrings.length > 1 && reportFile.open('w')){
                                  reportFile.write(fileStrings.join("\r"));
                                  reportFile.close();
                        }
              }
              
              app.scriptPreferences.userInteractionLevel=UserInteractionLevels.INTERACT_WITH_ALL;
              

               

              So, this will ask you to choose the folder that contains the InDesign documents you want link reports on. It won't descend into subfolders. If your files aren't all in one folder, you can drag aliases/shortcuts into one folder and it should follow them. It will then ask you for a folder to save the report files in. It's set up to make one .csv for each document, and it doesn't produce them for documents that have no links.

               

              Let me know if the file format I've chosen doesn't work for you, or if you'd rather have all of it in one document, or more fields, or whatever.

               

              Tested on CS5 on the Mac.

              • 4. Re: Batch Retrieve Image links
                KuddRoww Level 1

                Hi Jeff,

                 

                Script works like a charm!

                 

                I can't thank-you enough.

                 

                Best wishes,

                 

                Kurtis

                • 5. Re: Batch Retrieve Image links
                  KuddRoww Level 1

                  Hi Jeff,

                   

                  How would I output into one document? I've been joining the *.CSV files into a single through command prompt, however it would be helpful to just have it happen automatically. I've managed to figure out how to add in and take out different criteria, such as adding in the link.date, but I can't wrap my brain around this!

                   

                  Thanks a million for all your help,

                   

                  Kurtis

                  • 6. Re: Batch Retrieve Image links
                    absqua Level 4

                    Sorry I don't have time right now to write out the code. You'll move the reportFile definition (giving it a name that doesn't come from a document) and first fileStrings member (with the column headers) out before the loop, and also move the file write out after the loop. I don't think anything else should have to change. I would imagine you'd also want to add another column with the document name for each record since they'll all be in the same file...

                     

                    I'll take a crack at it Monday if you don't have anything yet and no one else chimes in.

                    • 7. Re: Batch Retrieve Image links
                      absqua Level 4

                      This will put it all into one file:

                       

                      var inFolder = Folder.selectDialog("Choose the folder that contains the InDesign documents.");
                      if(inFolder === null){
                          exit();
                      }
                      var reportFile = File(Folder.desktop + "/Link Report.csv").saveDlg("Save the report.");
                      if(reportFile === null){
                          exit();
                      }
                      
                      var files = inFolder.getFiles("*.indd"),
                          fileStrings = ["\"document\",\"link\",\"status\",\"date\",\"complete name\""],
                          doc, i, l, link, j, k;
                      
                      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
                      
                      for(i = 0, l = files.length; i < l; i++) {
                          doc = app.open(files[i], false);
                        
                          for(j = 0, k = doc.links.length; j < k; j++) {
                              link = doc.links[j];
                              fileStrings[fileStrings.length] = "\"" + doc.name + "\",\"" + link.name + "\",\"" + link.status.toString() + "\",\"" + 
                                                                  link.date.toString() + "\",\"" + link.filePath + "\"";
                          }
                      
                          doc.close(SaveOptions.NO);
                      }
                      
                      if(fileStrings.length > 1 && reportFile.open('w')){
                          reportFile.write(fileStrings.join("\r"));
                          reportFile.close();
                      }
                      
                      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
                      

                       

                      Jeff

                      1 person found this helpful
                      • 8. Re: Batch Retrieve Image links
                        KuddRoww Level 1

                        Jeff,

                         

                        Works like a charm.

                         

                        Thanks!

                         

                        Kurtis