• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

relink images with different names

Contributor ,
Jan 27, 2015 Jan 27, 2015

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

5.3K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jan 27, 2015 Jan 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

Likes

Translate

Translate
Mentor ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Hi,

Try this one:

var 

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

  cLink, cFile,

UIchoice = mDialog (); 

 

while ( cLink = mLinks.pop() ) { 

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

  cFile = File(UIchoice.source + "/" + cLink.name.replace(UIchoice.search,UIchoice.replace) ); 

  if ( !cFile.exists ) continue; 

  cLink.relink(cFile); 

  }

function mDialog ()

{

var

sourceFolder = null,

resObj = {

search: "",

replace: "",

source: sourceFolder

},

w1 = new Window("dialog","Link rename rule", undefined, {closeButton: false}),  

mPanel = w1.add("panel", undefined),

mStat1 = mPanel.add("statictext", undefined, "Current source folder:  "),

mStat2 = mPanel.add("statictext", undefined, "unknown"),

mChangeButton = mPanel.add("button", undefined, "Choose a file"),

mLine = mPanel.add("panel", [0,0,2,2]),

mSearch = mPanel.add("group"),

mSearchStat = mSearch.add("statictext", undefined,"Search for: "),

mSearchEdit = mSearch.add("edittext", undefined,""),

mReplace = mPanel.add("group"),

mReplaceStat = mReplace.add("statictext", undefined,"Replace with: "),

mReplaceEdit = mReplace.add("edittext", undefined,""),

mButtons = mPanel.add("group"),

mCan = mButtons.add ('button', undefined, "Cancel", {name:"Cancel"}),

mOK = mButtons.add ('button', undefined, "OK", {name:"OK"});

mChangeButton.onClick = function(){

var mChoice = Folder.selectDialog("Choose a source folder");

resObj.source = mChoice;

if(!mChoice) {

mOK.enabled = false;

mStat2.text = "unknown";

return;

}

mChoice = mChoice.fsName.split("\\");

mStat2.text = mChoice[0] + "/.../" + mChoice[mChoice.length - 1];

mOK.enabled = true;

}

//

mChangeButton.alignment = "left";

mStat2.alignChildren = "right";

mLine.alignment = "fill";

mSearch.alignment = mReplace.alignment = "right";

mButtons.alignment = "center";

mOK.enabled = false;

mSearchEdit.characters = mReplaceEdit.characters = 12;

mStat2.characters = 30;

mSearchEdit.active = true;

//

if (w1.show() == 1) {

resObj.search = mSearchEdit.text;

resObj.replace = mReplaceEdit.text;

return resObj;

}

else

exit();

}

Jarek

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Thank you Jarek! This was exactly what I meant

I'm sure other people find these useful too!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Good Dsay

So basically i have 357 images with the work (filename)_copy.psd that i have renamed to (filename)_bitmap.psd

do I jsut add this script to the scrips paneil?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

LATEST

Jarek... you are a legend

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

I've been trying to write/find a script like this original script for days and nothing has worked yet. How would I tweak it so the script would look for the missing links in the same folder relative to the open file every time instead of needing to select it? All of our links are in a folder called Links and we swap psds for pngs as part of our process and a one click solution would save us the most time.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Building off what I was talking about here: https://community.adobe.com/t5/indesign/rename-with-suffix-and-relink-an-selection-images/m-p/119875...

Assumes the missing link would have been in the same folder as the png and had the same name.

 

 

var ags = app.activeDocument.allGraphics;
var extRegEx = /\.[a-zA-Z]+$/gi;
var linkExt = ".png";
var aLink, linkName;
for (var i = 0; i < ags.length; i++) {
   try {
       aLink = ags[i].graphics[0].itemLink;
       if (aLink.status == LinkStatus.MISSING) {
           linkName = aLink.filePath.replace(extRegEx, linkExt);
           aLink.relink(File(linkName));
       }
   } catch(e) {}
}

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 11, 2021 Jan 11, 2021

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines