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
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
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
Copy link to clipboard
Copied
Thank you Jarek! This was exactly what I meant
I'm sure other people find these useful too!
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?
Copy link to clipboard
Copied
Jarek... you are a legend
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.
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) {}
}
Copy link to clipboard
Copied
Hi Jarek,
This script has been a massive time saver for me in InDesign. I need to do the same thing in Illustrator but could not get this script to work. Do you have a version for Illustrator? Thanks in advance.
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.