Skip to main content
Participant
May 22, 2015
Question

Change link path

  • May 22, 2015
  • 1 reply
  • 1285 views

I am looking for a way to change the file path of all my links in a document. I just need to remove part of the file path...

If the original file path is
/Volumes/My Passport/HiRes/990/9906.psd

and I need to make it

HiRes/990/990.psd

Is there an action script or some hidden trick to rename all the links?

I'm working on a mac in OS 10.9.5

Thanks for any help!

This topic has been closed for replies.

1 reply

Daniel Sterchi
Inspiring
May 25, 2015

Hi sketcg

I have put together a few lines. Try them if the meet your needs.

Would like to hear what you think.

kind regards

Daniel (from Switzerland)

/*

* written by Daniel Sterchi moonsoft.ch GmbH

*/

main();

exit();

function main() {

   

    if (app.documents.length > 0) {

       

        const delimiter = "/";      // "/" for mac "\\" for windows at lieast I think so (have a mac)

        // the active document

        var myDoc = app.activeDocument;

        // get all the links of this document

        var oldLinks = myDoc.links.everyItem().getElements();

       

        // if there are any links

        if (oldLinks.length > 0) {

            // open a dialog

            var newPath = new Folder(oldLinks[0].filePath).selectDlg("Choose a directory").fsName;

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

               

                // to get the filename of the Link.

                // for windows you can use the folowing code

                //      var myFileName = oldLinks.filePath;

                //      myFileName = myFileName.substr(myFileName.lastIndexOf(delimiter) + 1, myFileName.length);

                //      var newFile = File(newPath + delimiter + myFileName);

               

                // This way you dont have to bother with HFS+ or UFS directory names with macs

                var oldFile = File(oldLinks.filePath);

                var newFile = File(newPath + delimiter + oldFile.name);

                oldLinks.relink(newFile);

            }

        }

        else alert("Information\nThis document has no links to pictures");

    }

    else alert("Warning\nNo document open");

   

    alert("Information\nI have done my job, what about yours");

}

Inspiring
May 25, 2015

Hi Daniel,

On line 12 in your comments you mention Windows possibly being back-slashes, that is true for Windows explorer but for InDesign JavaScript it is forward-slashes.

For example:

"/v/Folder Name/File Name.indd"

or

"//server.address.com/Folder Name/File Name.jsx"

Regards,

Brett

Daniel Sterchi
Inspiring
May 25, 2015

Hi Brett

Thats good news. I just don't have windows so I can't test it.

Thanks for your input.

Daniel (from Switzerland)