Skip to main content
dulajun
Inspiring
April 6, 2012
Answered

How to check if a link reside inside a folder called Links beside the document?

  • April 6, 2012
  • 1 reply
  • 1289 views

How to check if a link reside inside a folder called Links beside the document?

var myDocument = app.activeDocument;

for(var myCounter = 0; myCounter < myDocument.allGraphics.length;myCounter++)

{

          var myGraphic = myDocument.allGraphics[myCounter];

          if(myGraphic.itemLink.status != LinkStatus.linkMissing)

          {

                    if (myGraphic.itemLink.filePath is Outside of the "Links" folder that reside beside this document)

                    {

                    }

          }

}

This topic has been closed for replies.
Correct answer Kasyan Servetsky

Main();

function Main() {

    var i, link,

    doc = app.activeDocument,

    linksPath = doc.filePath.fsName + "\\Links",

    links = doc.links;

   

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

        link = links;

        if(link.status != LinkStatus.linkMissing) {

            if (File(link.filePath).parent.fsName === linksPath) {

                $.writeln(i + " - " + link.name + " - is inside 'Links' folder");

            }

            else {

                $.writeln(i + " - " + link.name + " - is outside 'Links' folder");

            }

        }

    }

}

1 reply

Kasyan Servetsky
Kasyan ServetskyCorrect answer
Legend
April 8, 2012

Main();

function Main() {

    var i, link,

    doc = app.activeDocument,

    linksPath = doc.filePath.fsName + "\\Links",

    links = doc.links;

   

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

        link = links;

        if(link.status != LinkStatus.linkMissing) {

            if (File(link.filePath).parent.fsName === linksPath) {

                $.writeln(i + " - " + link.name + " - is inside 'Links' folder");

            }

            else {

                $.writeln(i + " - " + link.name + " - is outside 'Links' folder");

            }

        }

    }

}

dulajun
dulajunAuthor
Inspiring
April 8, 2012

OK, Thanks, but:

What does function $.writeln do?

How to select the links in the Links panel instead of reporting?

Kasyan Servetsky
Legend
April 8, 2012

What does function $.writeln do?

It writes the line to JS console in ESTK (just for demonstration)

How to select the links in the Links panel instead of reporting?

There is no need to select anything to process by a script. Instead of $.writeln you should call a function which would do something useful for you — for example, relink it to another image, remove the link, etc.

Anyway, if you want to select a link in the Links panel, you can do this by selecting the image like so:

...
else {      app.select(link.parent);      alert("This link is outside 'Links' folder");      exit(); }
...

This selects the image — parent of the link — gives a warning and exits the script.