Skip navigation
Currently Being Moderated

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

Apr 6, 2012 5:49 AM

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)

                    {

                    }

          }

}

 
Replies
  • Currently Being Moderated
    Apr 7, 2012 10:25 PM   in reply to Abdulaziz Junaid
    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[i];
            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");
                }
            }
        }
    }
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2012 1:03 AM   in reply to Abdulaziz Junaid

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 8, 2012 8:23 AM   in reply to Abdulaziz Junaid

    You can't select links in the Links panel by script. But you can relink links to images located in a folder. As I said before, you don't need to highlight links in the panel. Here is a script that does the job. You can rework it to your needs: add two if statements -- one to check if the link is missing and another to check if it  is inside the Links folder.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points