7 Replies Latest reply on Dec 5, 2013 3:43 PM by Soteriologist

    Edit code for change drive letters in paths for links, to also work with Fonts that have been moved.

    Soteriologist Level 1

      I have the following code that looks through my links and changes all of the drive letters to the new locations where they exist.  So if something stays in the same folder structure, but moves to a new drive E: and InDesign can not longer find it, you can run the code and have it fix them all.

       

      Well I want to do the same but for fonts that have also moved.

      Thank you in advance for any and all help!

       

       

      if (app.documents.length == 0) {
          err("No open document. Please open a document and try again.", true);
      }
      
      if (File.fs != "Windows") {
          err("This script is for Windows only.");
      }
      
      var myDoc = app.activeDocument;
      var myLinks = myDoc.links;
      var myCounter = 0;
      
      if (myLinks.length == 0) {
          err("This document doesn't contain any links.", true);
      }
      
      var mySettings = CreateDialog();
      
      for (i = myLinks.length-1; i >= 0 ; i--) {
          var myLink = myLinks[i];
          if ( myLink.status == LinkStatus.LINK_MISSING || (myLink.status != LinkStatus.LINK_MISSING && mySettings[2] == false) ) {
              var myOldPath = myLink.filePath;
              var myNewPath = myOldPath.replace(mySettings[0] + ":\\", mySettings[1] + ":\\");
              var myNewFile = new File(myNewPath);
              if (myNewFile.exists) {
                  myLink.relink(myNewFile);
                  try {
                      myLink.update();
                  } 
                  catch(e) {}
                  myCounter++;
              }
          }
      }
          
      if (myCounter == 1) {
          alert("One file has been relinked.", "Finished");
      }
      else if  (myCounter > 1) {
          alert(myCounter + " files have been relinked.", "Finished");
      }
      else {
          alert("Nothing has been relinked.", "Finished");
      }    
      
      function err(e, icon){
          alert(e, "Change drive letter in path", icon);
          exit();
      }
      
      function CreateDialog() {
          var myDrives = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "y", "Z"];
          var myDialog = new Window("dialog", "Change drive letter in path");
          var myPanel = myDialog.add("panel", undefined, "");
          myPanel.orientation = "column";
          myPanel.alignChildren = "left";
          var myGroup = myPanel.add("group");
          myGroup.orientation = "row";
          var myStText1 = myGroup.add("statictext", undefined, "Change ");
          var myDropDownList1 = myGroup.add("dropdownlist", undefined, myDrives);
          if (app.extractLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_Ddl1") != "") {
              myDropDownList1.selection = myDropDownList1.items[app.extractLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_Ddl1")];
          }
          else {
              myDropDownList1.selection = myDropDownList1.items[2];
          }
          var myStText2 = myGroup.add("statictext", undefined, " to ");
          var myDropDownList2 = myGroup.add("dropdownlist", undefined, myDrives);
          if (app.extractLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_Ddl2") != "") {
              myDropDownList2.selection = myDropDownList2.items[app.extractLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_Ddl2")];
          }
          else {
              myDropDownList2.selection = myDropDownList2.items[3];
          }
          
          var myCheckBox = myPanel.add("checkbox", undefined, "relink only missing links");
          if (app.extractLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_checkbox") != "") {
              myCheckBox.value = eval(app.extractLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_checkbox"));
          }
          else {
              myCheckBox.value = true;
          }
          var myButtonsGrp = myDialog.add("group");
          var myOkBtn = myButtonsGrp.add("button", undefined, "Ok", {name:"ok"});
          var myCancelBtn = myButtonsGrp.add("button", undefined, "Cancel", {name:"cancel"});
      
          myOkBtn.onClick = function() {
              if (myDropDownList1.selection.index == myDropDownList2.selection.index) {
                  alert("Both drive letters should not be the same.", "Change drive letter in path");
              }
              else {
                  myDialog.close(1);
              }
          }
      
          var myDialogResult = myDialog.show();
          if (myDialogResult == 1) {
              app.insertLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_Ddl1", myDropDownList1.selection + "");
              app.insertLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_Ddl2", myDropDownList2.selection + "");
              app.insertLabel("Kas_UpdatePathNamesAfterDriveLetterChange_3.0_checkbox", myCheckBox.value + "");
              return [ myDropDownList1.selection.text, myDropDownList2.selection.text, myCheckBox.value ];
          }
          else {
              exit();
          }
      }