Home > InDesign Scripts > Search links file names

Search links file names

Like we did searching through paragraph style names, in this little snippet we will search through links file names.


First thing we have to do is to get document links. Next, we set search string, then create Array for found links where we will put file names, and at the end, we create loop. In loop, we are extracting link name, converting it to lowercase, and matching with searching string which is also converted to lowercase. If we have match, link is pushed into foundLinks Array.

myLinks = app.activeDocument.links;
searchString = new String('0602');
var foundLinks = new Array();
for(var i=0; i < myLinks.length; i++){
    var myLinkName = myLinks[i].name;
    myLinkName = myLinkName.toLowerCase();
    if(myLinkName.indexOf(searchString.toLowerCase()) != -1)foundLinks.push(myLinks[i]);
}
alert('Search: ' + searchString + '\rFound: ' + foundLinks.length);

So, now we have foundLinks which holds, not just link names, it holds link objects, so you can extract link names, parent pages, and all info that you want. All is now up to you and your needs 🙂

Leave a comment