13 Replies Latest reply on Nov 30, 2018 8:06 AM by Kasyan Servetsky

    Path change

    schiuma24 Level 1

      is there a way to make a script to change just a part of the path to all the links.

      lets say all the docks links are in //server_1/ and i have //server_2/ with the same folder tree as server 1 so by just change the 1 to 2 the files would be there..can that be done at once with java script?

        • 1. Re: Path change
          [Jongware] Most Valuable Participant

          I'm guessing you can.


          The filePath property of a link is just a Javascript string, and you can manipulate it at will. You can't immediately change the file name of the link, as it is a read-only property, but you can copy the string, change it, then feed it back into the link using the relink method.

          • 2. Re: Path change
            Kasyan Servetsky Level 5

            I wrote a few scripts that update, change path, relink links. Here is one of them, which, I think, is suits best to what you ask.

            I called it 'Change paths of links'.

            BTW, question to native English speakers: which of the following is gramatically correct?

            • Change paths of links
            • Change paths of the links
            • Change the paths of the links
            • Change links' paths
            • Change the links' paths


            When you run the script a dialog box appears with two text fields, where you specify a platform-specific path name, or a path in a platform-independent format known as universal resource identifier (URI) notation, or Mac OS 9 path name (for Mac).

            For example any of the following notations are valid:



            c:\dir\file(Windows path name)

            /c/dir/file(URI path name)


            // naming convention (UNC) path name of the form //servername/sharename)



            \\\Test\images (Windows path name)

            \\Apple\Test\images (Windows path name)


            where IP address of the server, Apple -- DNS name of the server, Test -- share name



            Thefollowing examples assume that the startup volume is MacOSX, and that there isa mounted volume Remote.

            /dir/file (Mac OS X path name)

            /MacOSX/dir/file(URI path name)

            MacOSX:dir:file(Mac OS 9 path name)

            /Remote/dir/file (URI path name)

            Remote:dir:file (Mac OS 9 path name)

            Remote/dir/file (Mac OS X path name)


            You can just copy a part of the path in Links panel and paste it to the script's dialog. In CS4, make sure to choose "Copy Platform Style Path" in context menu.


            The caseof the characters doesn’t matter: you can type both in upper and lowercase inthe script's dialog. For example — Test, test, TEST, TeSt — are all the samefor the script.

            Change paths of links.png

            // Change paths of links.jsx
            // Script for InDesign CS3 and CS4 -- changes paths of links in the active document.
            // Version 1.0
            // May 13 2010
            // Written by Kasyan Servetsky
            // http://www.kasyan.ho.com.ua
            // e-mail: askoldich@yahoo.com
            var gScriptName = "Change paths of links";
            var gScriptVer = 1;
            var gOsIsMac = (File.fs == "Macintosh") ? true : false;
            var gSet = GetSettings();
            if (app.documents.length == 0) {
                 ErrorExit("No open document. Please open a document and try again.", true);
            var gDoc = app.activeDocument;
            var gLinks = gDoc.links;
            var gCounter = 0;
            if (gLinks.length == 0) {
                 ErrorExit("This document doesn't contain any links.", true);
            //======================= FUNCTIONS =============================
            function CreateDialog() {
                 var dialog = new Window("dialog", gScriptName);
                 dialog.orientation = "column";
                 dialog.alignChildren = "fill";
                 var panel = dialog.add("panel", undefined, "Settings");
                 panel.orientation = "column";
                 panel.alignChildren = "right";
                 var group1 = panel.add("group");
                 group1.orientation = "row";
                 var findWhatStTxt = group1.add("statictext", undefined, "Find what:");
                 var findWhatEdTxt = group1.add("edittext", undefined, gSet.findWhatEdTxt);
                 findWhatEdTxt.minimumSize.width = 300;
                 var group2 = panel.add("group");
                 group2.orientation = "row";
                 var changeToStTxt = group2.add("statictext", undefined, "Change to:");
                 var changeToEdTxt = group2.add("edittext", undefined, gSet.changeToEdTxt);
                 changeToEdTxt.minimumSize.width = 300;
                 var btnGroup = dialog.add("group");
                 btnGroup.orientation = "row";
                 btnGroup.alignment = "center";
                 var okBtn = btnGroup.add("button", undefined, "Ok");
                 var cancelBtn = btnGroup.add("button", undefined, "Cancel");
                 var showDialog = dialog.show();
                 if (showDialog== 1) {
                      gSet.findWhatEdTxt = findWhatEdTxt.text;
                      gSet.changeToEdTxt = changeToEdTxt.text;
                      app.insertLabel("Kas_" + gScriptName + "_ver_" + gScriptVer, gSet.toSource());
            function Main() {
                 WriteToFile("\r--------------------- Script started -- " + GetDate() + " ---------------------\n");
                 for (var i = gLinks.length-1; i >= 0 ; i--) {
                      var currentLink = gLinks[i];
                      var oldPath = currentLink.filePath;
                      oldPath = oldPath.replace(/:|\\/g, "\/");
                      oldPath = oldPath.toLowerCase();
                      gSet.findWhatEdTxt = gSet.findWhatEdTxt.replace(/:|\\/g, "\/");
                      gSet.changeToEdTxt = gSet.changeToEdTxt.replace(/:|\\/g, "\/");
                      gSet.findWhatEdTxt = gSet.findWhatEdTxt.replace(/([A-Z])(\/\/)/i, "/$1/");
                      gSet.changeToEdTxt = gSet.changeToEdTxt.replace(/([A-Z])(\/\/)/i, "/$1/");
                      gSet.findWhatEdTxt = gSet.findWhatEdTxt.toLowerCase();
                      gSet.changeToEdTxt = gSet.changeToEdTxt.toLowerCase();
                      if (File.fs == "Windows") oldPath = oldPath.replace(/([A-Z])(\/\/)/i, "/$1/");
                      var newPath = oldPath.replace(gSet.findWhatEdTxt, gSet.changeToEdTxt);
                      if (File.fs == "Windows") {
                           newPath = newPath.replace(/([A-Z])(\/\/)/, "/$1/");
                      else if (File.fs == "Macintosh") {
                           newPath = "/Volumes/" + newPath;
                      var newFile = new File(newPath);
                      if (newFile.exists) {
                           WriteToFile("Relinked \"" + newPath + "\"\n");
                      else {
                           WriteToFile("Can't relink \"" + newPath + "\" because the file doesn't exist\n");
                 WriteToFile("\r--------------------- Script finished -- " + GetDate() + " ---------------------\r\r");
                 if (gCounter == 1) {
                      alert("One file has been relinked.", "Finished");
                 else if  (gCounter > 1) {
                      alert(gCounter + " files have been relinked.", "Finished");
                 else {
                      alert("Nothing has been relinked.", "Finished");
            function GetSettings() {
                 var settings = eval(app.extractLabel("Kas_" + gScriptName + "_ver_" + gScriptVer));
                 if (settings == undefined) {
                      if (gOsIsMac) {
                           settings = { findWhatEdTxt:"//ServerName/ShareName/FolderName", changeToEdTxt:"ShareName:FolderName" };
                      else {
                           settings = { findWhatEdTxt:"ShareName:FolderName", changeToEdTxt:"//ServerName/ShareName/FolderName" };
                 return settings;
            function ErrorExit(myMessage, myIcon) {
                 alert(myMessage, gScriptName, myIcon);
            function WriteToFile(myText) {
                 var myFile = new File("~/Desktop/" + gScriptName + ".txt");
                 if ( myFile.exists ) {
                      myFile.seek(0, 2);
                 else {
            function GetDate() {
                 var myDate = new Date();
                 if ((myDate.getYear() - 100) < 10) {
                      var myYear = "0" + new String((myDate.getYear() - 100));
                 } else {
                      var myYear = new String ((myDate.getYear() - 100));
                 var myDateString = (myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myYear + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();
                 return myDateString;
            • 3. Re: Path change
              [Jongware] Most Valuable Participant

              Not a native speaker, but I'd suggest "Change the path of each link" 

              • 4. Re: Path change
                Kasyan Servetsky Level 5

                Not a native speaker, but I'd suggest "Change the path of each link"

                Thanks, I'll change it.



                • 5. Re: Path change
                  schiuma24 Level 1

                  as a native speaker,


                  Change paths of links

                  • 6. Re: Path change
                    Emanuele Radaelli

                    From CS4 there's the "Relink to folder" command from the links palette.

                    There should be some script facility too...

                    • 7. Re: Path change
                      Kasyan Servetsky Level 5

                      There should be some script facility too...

                      No, this command is unavailable to scripting

                      • 8. Re: Path change
                        Bill Planey Level 1

                        I am trying to change the paths associated with links that think they are on Windows still, and I am on a Mac. I plug the directory path as noted in the links palette up to the file name in the Find field and the corrected directory path on the Mac in the Change field.


                        The script runs and claims to have changed the paths, but they are not changed.


                        Is this script capable of fixing Windows-to-Mac files?

                        • 9. Re: Path change
                          JensPeters Level 1

                          Dear Kasyan,

                          this script is worth a fortune! "They" changed the path to our media library without notifying anybody, making all the links (several hundreds per document) worthless.

                          I tried your script on a Windows 7 / CS6 system, and it worked without any hickups. I'll try it with CC 2015 some time.


                          Thank you so much for your work!


                          Best, Jens

                          • 10. Re: Path change
                            Kasyan Servetsky Level 5

                            Thanks for your kind words, Jens!

                            By the way, here is the link to the script on my site.


                            — Kasyan

                            • 11. Re: Path change

                              Hi Kasyan! 


                              Thank you for the great script!  It works extremely well for except for one problem...  It changes all my file names to all lower case.  It doesn't actually save over the files, it just changes the files to lower case in the inDesign links pallet and if I click the edit button the files opens up also with the all lower case files name but the original file is not changed.


                              I'm running inDesign 13.1 x64

                              Windows 10 pro version 1709

                              OS build 16299.492



                              thank you in advance for your help! 


                              • 12. Re: Path change
                                studiotrope design

                                Have successfully used it to change an individual link, but was thinking that it would be able to find and replace a portion of the link across multiple missing links. For example:


                                These are two links that I was able to reconcile using this script.

                                Find what: \Volumes\STT Marketing\02_SPECIFIC RESPONSES\project\SOQ\Consultants\arch\sample work\Images\sample03.jpg


                                Change to: M:\02_SPECIFIC RESPONSES\project\SOQ\Consultants\arch\sample work\Images\sample03.jpg


                                Instead, if I try the following, it says that all the links in the document have been updated, but they’re still shown as missing in the links window:


                                Find what: \Volumes\STT Marketing\02_specific responses\


                                Change to: M:\02_specific responses\


                                Any thoughts or am I not using the right notation?

                                • 13. Re: Path change
                                  Kasyan Servetsky Level 5

                                  Some people tell me that the script works well for them; some say it ain't working.

                                  Sometimes -- though quite rarely -- I use it at my work and it works for me without glitches.

                                  To solve the problem I have to open a doc in Indy and run the script in debugger (ESTK) to see what and where goes wrong.

                                  Your network set up can be different than mine. For example, once I was writing a script processing links located on client's network. It worked properly on my network but failed on the client's side. Finally, I went to his office and found out that the link paths there had a strange prefix (I couldn't guess it). After I added the prefix, it worked perfectly.


                                  So, I can suggest the following options:

                                  • you send me a test doc with some links so I could to attempt recreate your problem (you know my e-mail)
                                  • try to debug it on your side via teamViewer


                                  I don't promise I will solve it: I will try to fix it if it won't take much time for me.


                                  — Kas