2 Replies Latest reply on Mar 18, 2016 12:26 AM by Evilia_77

    script doesn't work anymore after updating indesign

    Evilia_77 Level 1

      Hi,

       

      I've updated my Indesign to the latest version. Now my script doesn't work anymore.


      Does anyone can help me?

       

      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.", "Batch update links script");
         exit();
      }
      
      
      if (myFilelist.length == 0) {
         alert("No files to open.", "Batch update links script");
         exit();
      }
      
      
      var myCounter = 1;
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
      
      
      // Progress bar -----------------------------------------------------------------------------------
      var myProgressWin = new Window ( "window", "Batch update links script" );
      var myProgressBar = myProgressWin.add ("progressbar", [12, 12, 350, 24], 0, myFilelist.length);
      var myProgressTxt = myProgressWin.add("statictext", undefined, "Starting updating 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];
         
         try {
             var myDoc = app.open(myCurrentFile, false);
             var myDocName = myDoc.name;
      
      
             // Progress bar -----------------------------------------------------------------------------------
             myProgressBar.value = myCounter;
             myProgressTxt.text = String("Updating file - " + myDocName + " (" + myCounter + " of " + myFilelist.length + ")");
             
             // Progress bar -----------------------------------------------------------------------------------
             UpdateAllOutdatedLinks();
             myDoc = myDoc.save();
             myDoc.close(SaveOptions.NO);
      
      
             myCounter++;
         }
         catch(e) {}
      }
      
      
         // Progress bar -----------------------------------------------------------------------------------
         myProgressWin.close();
         // Progress bar -----------------------------------------------------------------------------------
      
      
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
      
      
      alert("Done.", "Batch update links 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 UpdateAllOutdatedLinks() {
         for (var myCounter = myDoc.links.length-1; myCounter >= 0; myCounter--) {
             var myLink = myDoc.links[myCounter];
             if (myLink.status == LinkStatus.linkOutOfDate) {
                 myLink.update();
             }
         }
      }
      //--------------------------------------------------------------------------------------------------------------