7 Replies Latest reply on Jun 24, 2014 1:14 AM by hasvi

    Correct my 'indesign file' move script

    hasvi Level 1

      Hi,

       

      How can I place the "Template File.indd" in newly created "Folder 1". Here my output file is saved as a "Template File.indd", now I want to create new folder name as like "Folder 1". Then I want to place the "Template File.indd" in "Folder 1".

       

      this is my code:

       

      var path = Folder.selectDialog ("Select folder");
      if(path==null)
      {
          exit();
          }
      
      
      var files = path.getFiles(/\.(indd?|indt?)$/i );
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
      
      
      try
      {
      myDocument = app.open(new File(files));
      myDocument.save(new File(path + "/" + "Template File.indd"));
      }
      catch(e)
      {
      alert ("Your folder permissible only one file of 'INDD' or 'INDT' file");
      exit();
      }
      

       

      by

      hasvi

        • 1. Re: Correct my 'indesign file' move script
          Chinnadk Level 4

          Hi Hasvi,

           

          Try this.

           

          var path = Folder.selectDialog ("Select folder");
          if(path==null)
          {
              exit();
              }
          var files = path.getFiles(/\.(indd?|indt?)$/i );
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
          try
          {
          myDocument = app.open(new File(files));
          myDocument.save(new File(path + "/Template File.indd"));
          var folder = new Folder(path + "/Folder1");
          folder.create();
          myDocument.close();
          var source = File(path + "/Template File.indd");
          var dest = new File(folder + "/Template File.indd");
          source.copy(dest);
          source.remove();
          }
          catch(e)
          {
          alert ("Your folder permissible only one file of 'INDD' or 'INDT' file");
          exit();
          }
          

           

          Regards,

          Chinna

          • 2. Re: Correct my 'indesign file' move script
            hasvi Level 1

            Hi chinna,

             

            I have combined 'PreferenceSettings()' in your script, here folders are created with 'NewTemplate.indt' file, but Preference setting is not updated in 'NewTemplate.indt' file.

             

             

            This is the combined code:

            var path = Folder.selectDialog ("Select folder"); 

            if(path==null) 

            exit(); 

            }

             

             

            var files = path.getFiles(/\.(indd?|indt?)$/i);

             

             

            if(files==0)   

            {

              alert("There is no 'indd'/'indt' file in your folder");

              exit();

              }

             

             

            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 

            try 

            myDocument = app.open(new File(files)); 

            myDocument.save(new File(path + "/NewTemplate.indt")); 

            var folder = new Folder(path + "/Template"); 

            folder.create(); 

            myDocument.close(); 

            var source = File(path + "/NewTemplate.indt"); 

            var dest = new File(folder + "/NewTemplate.indt"); 

            source.copy(dest); 

            source.remove(); 

            catch(e) 

            alert ("Your folder permissible only one file of 'INDD' or 'INDT' file"); 

            exit(); 

             

             

            PreferenceSettings();

            function PreferenceSettings()

            {

            //this is 'Advanced Type' default setting

            myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;

            myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

            myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

            myDocument.textPreferences.superscriptPosition=33;

            myDocument.textPreferences.superscriptSize=70;

            myDocument.textPreferences.subscriptPosition=33;

            myDocument.textPreferences.subscriptSize=70;

            myDocument.textPreferences.smallCap=75;

            }

             

             

            main();

            function main(){

                  var progress_win = new Window ("palette");

            var progress = progress_bar(progress_win, 2, 'Processing ... Completed');

                delay(1);

                  progress.value = progress.value+1;

                delay(1);

                progress.parent.close();

                }

            // delay function found here

            //found here http://www.wer-weiss-was.de/theme157/article1143593.html

              function delay(prmSec){

              prmSec *= 1000;

              var eDate = null;

              var eMsec = 0;

              var sDate = new Date();

              var sMsec = sDate.getTime();

              do {

              eDate = new Date();

              eMsec = eDate.getTime();

              } while ((eMsec-sMsec)<prmSec);

              }

            /**

            * Taken from ScriptUI by Peter Kahrel

            *

            * @param  {Palette} w    the palette the progress is shown on

            * @param  {[type]} stop [description]

            * @return {[type]}      [description]

            */

            function progress_bar (w, stop, labeltext) {

            var txt = w.add('statictext',undefined,labeltext);

            var pbar = w.add ("progressbar", undefined, 1, stop);

            pbar.preferredSize = [300,20];

            w.show ();

            return pbar;

            }

             

             

            FYI see error report below:

            1.png

            by

            hasvi

            • 3. Re: Correct my 'indesign file' move script
              Chinnadk Level 4

              Hi Hasvi,

               

              The function "PreferenceSettings()" should be called before the document closed.

               

              Place this line

              PreferenceSettings();

              before

              myDocument.close();

               

              Regards,

              Chinna

              • 4. Re: Correct my 'indesign file' move script
                hasvi Level 1

                Hi chinna,

                 

                now its working but preference settings are not changed.

                 

                by

                hasvi

                • 5. Re: Correct my 'indesign file' move script
                  Chinnadk Level 4

                  Sorry, place it above the below line.

                  myDocument.save(new File(path + "/NewTemplate.indt"));

                  • 6. Re: Correct my 'indesign file' move script
                    hasvi Level 1

                    thanks chinna,

                     

                    I have assign log report in my document file path, but now my log report has to place in newly created 'Template' folder, what is the code for instead of below code

                     

                     

                        var myTextFile = new File(myDocument.filePath + "/Mismatched Generic Style Log Report.csv")

                     

                    by

                    hasvi

                    • 7. Re: Correct my 'indesign file' move script
                      hasvi Level 1

                      Hi chinna,

                       

                      I am going to insert this function in above script. Here my log report 'Log Report.csv' has to create in newly created 'Template' folder.

                      function MasterPageTextFrameLogReport()

                      {

                          var master = myDocument.masterSpreads;

                          var contents = "";

                          for(var i =0;i<master.length;i++)

                          {

                                  for(var j =0;j<master[i].textFrames.length;j++)

                                  {

                                          if(master[i].textFrames[j].parentPage != null)

                                          {

                                              if(master[i].textFrames[j].contents !="")

                                          {

                                              contents +="\""+ master[i].name + "\",\"" + master[i].textFrames[j].contents + "\"\r";

                                          }

                                          }

                                      }

                              }

                          var file = new File(myDocument.filePath + "/Log Report.csv");

                          file.open("w");

                          file.write(contents);

                          file.close();

                        }

                      by

                      hasvi