Copy link to clipboard
Copied
Hi folks,
I have a script to relink the images from the different selected folders, now I want the script will relink the images to matches with partial names, is it possible for example
In indesign document the linked image name will
200400_250500_filename_R1_cmyk_5.tif
Now the revised image will updated in the selected folder with the name of
200400_250500_filename_R2_cmyk_5.tif
The script need to match the link name in indesign document and selected folder with this "200400_250500" number and relink don't consider the remainning part of the link name.
Please share your thoughts...
Copy link to clipboard
Copied
Hello Rocky,
Give the below code a try for your needs......
var doc = app.documents[0];
sourceFolder = Folder.selectDialog("Select a Source Folder");
if (sourceFolder != null){
}else{
exit();
}
var myFilesToLink = sourceFolder.getFiles();
try {
for(var i = 0; i < doc.links.length; i++){
if (doc.links[i].name.match(/^\d{6}_\d{6}\_filename_\w+\_cmyk_\d+\.[a-z]+/gi,)){
var myLinks = doc.links[i];
var myLink = doc.links[i].name.replace(/^(\d{6}_\d{6})(\_filename_\w+\_cmyk_\d+\.[a-z]+)/gi, '$1');
for (var f = 0; f <myFilesToLink.length; f++) {
if (myFilesToLink[f].name.match(/^\d{6}_\d{6}\_filename_\w+\_cmyk_\d+\.[a-z]+/gi,)){
var myRevisedFile = myFilesToLink[f];
var myFilesToLinkName = myFilesToLink[f].name.replace(/^(\d{6}_\d{6})(\_filename_\w+\_cmyk_\d+\.[a-z]+)/gi, '$1');
if (myFilesToLinkName.match(myLink)) {
myLinks.relink(myRevisedFile);
}
}
}
}
}
alert("Done!\nSearching for any matches and relinking completed!");
} catch (e) {}
Regards,
Mike
Copy link to clipboard
Copied
Share the script that you have got and we can try and make changes to it. It is doable.
-Manan
Copy link to clipboard
Copied
Sorry for delay!
I have shared my part of the code below
processFile()
function processFile() {
doc = app.activeDocument;
var myLinks = doc.links;
for(a=0; a<myLinks.length; a++){
var singleImages = String(linksDetails).split(",");// images chosen from the selected folders
for(b=0; b<singleImages.length; b++){
if (myLinks[a].linkType != "Internal Linked Story" && myLinks[a].linkType != "Internal Linked Object") {
var newLinkName = singleImages[b].replace(/^.+\//, "");
// var newSplitPath = singleImages[b].substr(0, singleImages[b].lastIndexOf("/") + 1);
var mySplitName = newLinkName.split("_");
var myFinalSplitName = mySplitName[0].concat("_"+mySplitName[1]);
//var myremFileName = newLinkName.split('_').slice('2').join('_');
if(myLinks[a].name.match(/\.(tif)$/)){
if(newLinkName.indexOf(myFinalSplitName)>-1) {
myLinks[a].show();
//Here is the line I can't able to relink the images name to match with partially
var newLinkPath = File(singleImages[b]);
myLinks[a].relink(newLinkPath);
break;
}
}
}
}
}
}
Please find the links name in the document as well as in the selected folder below :
In indesign document the linked image name has to be
200400_250500_filename_R1_cmyk_5.tif
Now the revised image will updated in the selected folder with the name of
200400_250500_filename_R2_cmyk_5.tif
I want the code will match the highlighted numbers in link names and relink don't consider the remaining part of the name.