4 Replies Latest reply on Nov 4, 2011 8:28 AM by gdomagalski

    Batch automation - need to remove “choose” popup for folder selection in the automation

    gdomagalski

      Am new to scripting, and am creating a script to batch automate CS5 .idml to CS4 .inx. I have found a few scripts out there close enough that I can modify, but they all include the same variable of selecting the folder to get the files to process. Even when I put the ("//server/directorypath/folder") in place, it still opens the popup to “choose” the folder I just told it to go to. In the end what I need is a place people can put their .idml files on the network and, through an action folder running the script from a dedicated machine with CS4, spit the .inx they need. I have figured out how to turn indd dialog/alerts on and off, but not this!

       

      How can I make the “var myFolder =” be a fixed location?? Everything I try seems to create an exception later in the script

       

      var myFolder = Folder.selectDialog("Select a folder with InDesign files to open");
      if (myFolder == null) exit();
      var myFilelist = [];
      var myAllFilesList = myFolder.getFiles();

        • 2. Re: Batch automation - need to remove “choose” popup for folder selection in the automation
          gdomagalski Level 1

          Thanks John, it took care of the popup, but presents alert stating “no files to open”. here is the full script I started out with. Aside from server location the only thing I changed was substituting indd with idml on line 20, and of course the file path. It also throws a “Done” alert at the end. I also moved the INTERACT_WITH_ALL (line 77) to the end, but isn't stopping the done alert.

           

          // Export to interchange script.jsx
          // Script for InDesign CS3.
          // Opens all InDesign documents in selected folder
          // and  exports them into 'Interchange Files' subfolder as inx files, which is created in the selected folder.
          // Version 1.0
          // Jan 28 2010
          // Written by Kasyan Servetsky
          // http://www.kasyan.ho.com.ua
          // e-mail: askoldich@yahoo.com
          //---------------------------------------------------------------------------------------- ----------------------
          var myInDesignVersion = Number(String(app.version).split(".")[0]);

           

          var myFolder = Folder.selectDialog("Select a folder with InDesign files to resave");
          if (myFolder == null) exit();
          var myFilelist = [];
          var myAllFilesList = myFolder.getFiles();

           

          for (var f = 0; f < myAllFilesList.length; f++) {
              var myFile = myAllFilesList[f];
              if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
                  myFilelist.push(myFile);
              }
          }
          if (myInDesignVersion < 5) {
              alert("This script is for InDesign CS3/4.", "Export to interchange script");
              exit();
          }

           

          if (myFilelist.length == 0) {
              alert("No files to open.", "Export to interchange script");
              exit();
          }

           

          var myExportFolder = new Folder( myFolder.fsName + "/Interchange Files/" );
          VerifyFolder(myExportFolder);

           

          var myCounter = 1;
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

           

          // Progress bar -----------------------------------------------------------------------------------
          var myProgressWin = new Window ( "window", "Export to interchange script" );
          var myProgressBar = myProgressWin.add ("progressbar", [12, 12, 350, 24], 0, myFilelist.length);
          var myProgressTxt = myProgressWin.add("statictext", undefined, "Starting exporting files");
          myProgressTxt.bounds = [0, 0, 340, 20];
          myProgressTxt.alignment = "left";
          myProgressWin.show();
          // Progress bar -----------------------------------------------------------------------------------

           

          for (var i = myFilelist.length-1; i >= 0; i--) {
                  var myCurrentFile = myFilelist[i];
                  var myNewName = GetNameWithoutExtension(myCurrentFile) + ".inx";
             
              try {
                  var myDoc = app.open(myCurrentFile, false);
                  var myDocName = myDoc.name;
                  var myDocFilePath = new File(myExportFolder.fsName + "/" + myNewName);

           

                  // Progress bar -----------------------------------------------------------------------------------
                  myProgressBar.value = myCounter;
                  myProgressTxt.text = String("Exporting file - " + myDocName + " (" + myCounter + " of " + myFilelist.length + ")");
                  // Progress bar -----------------------------------------------------------------------------------

           

                  myDoc.exportFile(ExportFormat.INDESIGN_INTERCHANGE, myDocFilePath);
                  myDoc.close(SaveOptions.NO);
                 
                  myCounter++;
              }
              catch(e) {
                  alert(e);
              }
          }

           

              // Progress bar -----------------------------------------------------------------------------------
              myProgressWin.close();
              // Progress bar -----------------------------------------------------------------------------------

           

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

           

          alert("Done.", "Export to interchange script");

           

          //---------------------------------------------------------------------------------------- ----------------------
          function VerifyFolder(myFolder) {
              if (!myFolder.exists) {
                  var myFolder = new Folder(myFolder.absoluteURI);
                  var myArray1 = new Array();
                  while (!myFolder.exists) {
                      myArray1.push(myFolder);
                      myFolder = new Folder(myFolder.path);
                  }
                  myArray2 = new Array();
                  while (myArray1.length > 0) {
                      myFolder = myArray1.pop();
                      if (myFolder.create()) {
                          myArray2.push(myFolder);
                      } else {
                          while (myArray2.length > 0) {
                              myArray2.pop.remove();
                          }
                          throw "Folder creation failed";
                      }
                  }
              }
          }
          //---------------------------------------------------------------------------------------- ----------------------
          function GetNameWithoutExtension(myFile) {
              var myFileName = myFile.name;
              var myIndex = myFileName.lastIndexOf( "." );
              if ( myIndex > -1 ) {
                  myFileName = myFileName.substr(0, myIndex);
              }
              return myFileName;
          }

          • 3. Re: Batch automation - need to remove “choose” popup for folder selection in the automation
            John Hawkinson Level 5

            Please paste scripts in the Advanced editor and use >> Syntax Highighting > Java.

             

            Perhaps your problem is you are using the wrong syntax for your path to the file. Try editing the original script script and adding:

             

            var myFolder = Folder.selectDialog("Select a folder with InDesign files to resave");
            alert("Set myFolder to "+myFolder.fsName);
            

             

            and then see exactly how the folder name is given and try using that.

            • 4. Re: Batch automation - need to remove “choose” popup for folder selection in the automation
              gdomagalski Level 1

              Beautiful! The alert changed my call from the the server name to “volumes” (as called from the box the script is running on).

               

              Can't thank you enough for you're Help John,

               

              Cheers!