Skip to main content
ascotto
Known Participant
January 27, 2015
Answered

relink images with different names

  • January 27, 2015
  • 2 replies
  • 9450 views

Hi all, I need to relink lots of -missing- images (i.e. "my_favourite_pic_001_LR.jpg") to their high resolution versions (i.e. "my_favourite_pic_001_HR.jpg"). So, is there a way to tell InDesign to 'read' all the characters but the last two before the dot, while searching for links? HR images are all in one folder, so there's no danger to relink wrong ones. I'm pretty a noob with js or applescript, but I'll be glad if someone of you could help me

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

Here is javascript (place and run from InDesign Script Panel):

var

  sourceFolder = Folder.selectDialog("Show me a source folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  if (cLink.status == LinkStatus.NORMAL) continue;

  cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );

  if ( !cFile.exists ) continue;

  cLink.relink(cFile);

  }

Jarek

2 replies

Inspiring
January 11, 2021

Worked perfectly! Thanks Jump_Over. I had over 150 images I had to quickly rename (using NameChanger) adding 'GG' (GG.jpeg). I thought I'd have to find/update each image one by one in Links panel. 

Jump_Over
Jump_OverCorrect answer
Legend
January 27, 2015

Hi,

Here is javascript (place and run from InDesign Script Panel):

var

  sourceFolder = Folder.selectDialog("Show me a source folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  if (cLink.status == LinkStatus.NORMAL) continue;

  cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );

  if ( !cFile.exists ) continue;

  cLink.relink(cFile);

  }

Jarek

ascotto
ascottoAuthor
Known Participant
January 28, 2015

It's amazing, thanks a lot! However, is there a way to add "MR" images or whatever two letters before the dot, to be all relinked to HR ones?

Jump_Over
Legend
January 28, 2015

Hi,

One can use regex in place on 1st parameter of replace method.

Line 08:

cFile = File(sourceFolder + "/" + cLink.name.replace(/.{2}\./,"HR.")

which means match "any two characters and period"

Jarek