Skip to main content
Known Participant
April 10, 2024
Question

Script to select links only in the panel

  • April 10, 2024
  • 4 replies
  • 1822 views

Hey guys.
I need help selecting links in the panel. Is there any script (or can someone help me create it) so that I can select the links in my document only in the links panel? And I also need the script to select only links that have a piece of the indd file name in their name.
Ex:
My indesign file has the name: "teste_name.indd"
My links have names:
test_name_img1.jpg
test_name_img2.jpg
test_name_img3.jpg
img_10
img_11

Then, the script will select only the links in the panel ((because these files (in the panel) are the ones whose name is the same as the file name.))
can anybody help me? 
I could only think of this, but it doesn't work:

var doc = app.activeDocument;
for (var d = doc.links.length-1; d >= 0; d--) {
     var link = doc.links[d];
     app.select(link);

     }


can anybody help me? I would need this script to add to another larger one that I am creating.
Exemple in image.

This topic has been closed for replies.

4 replies

Inspiring
April 11, 2024

Well, always is the way...

I am not scripter but..... scripters can use this approach: 

Select your links in link's panel, then script will generate captions, and will group captions with links (Frame on page). Then script will search links name in this captions frame and delete whole group. So I bet, this is possible 🙂 

Convince me it's not possible 🙂

Yt/DtptutorialyCZ

 

rob day
Community Expert
Community Expert
April 11, 2024

Select your links in link's panel,

 

There's no method in the scripting API that will get the panel's selected links. If there are linked objects on a spread that have been selected, then yes.

rob day
Community Expert
Community Expert
April 12, 2024
quote

After Link is selected - Invoke can be used.

 

Maybe @eusoujpg  can confirm, but I don’t think there is a selection in the Links panel—the script needs to make the selection of a range of items.


By @rob day

 

If you select few items on the list - this will return list of selected links:

Copy Info for Selected Links Copy Info for Selected Links Panel Menus:Links

132619

 

 

 

But there is a problem - it will return just the name of the file - with path if you enable it in options.

 

Solution with generating Captions is correct - will create captions for ONLY selected instances:

 

 


If you select few items on the list - this will return list of selected links

 

But there is no selection @eusoujpg wants to script a the selection

Community Expert
April 11, 2024

As already mentioned script rarely has any capability like selecting objects to do anything on the native panels. So you will need to let us know what you want to do after selecting the items we could explore the possibility of acheiving that.

-Manan

-Manan
rob day
Community Expert
Community Expert
April 10, 2024

Hi @eusoujpg , If by select you mean you want to select the items in the Link panel’s list (not select the linked assets on the pages), that can’t be done via scripting

brian_p_dts
Community Expert
Community Expert
April 10, 2024

What do you want to do with the link after you select it? Do you want to manipulate its parent frame, or something else? You can't select across multiple spreads, so just selecting, even as an ADD TO SELECTION would not work. To test the name of the indd doc against the link name, you could try the following: 

var doc = app.activeDocument;
var nm = new RegExp(doc.name.replace(/\.indd$/i,""),"i");
for (var d = doc.links.length-1; d >= 0; d--) {
     var link = doc.links[d];
     if (nm.test(link.name) { 
        //do something with link. link.parent would get its frame
     }
}

 

eusoujpgAuthor
Known Participant
April 12, 2024

these links will be relinked to another local folder. It's just a way to automate, as the other links that I didn't select will be relinked by other files.

brian_p_dts
Community Expert
Community Expert
April 12, 2024

If you want to relink to another folder, then use my snippet above and in the comment block, try something like:

 

link.relink(File(someFolder +"/" + link.name);