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)
{
}
}
}
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");
}
}
}
}
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.
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.
North America
Europe, Middle East and Africa
Asia Pacific