var myDoc = app.activeDocument;
var myLinks = myDoc.links;
for (i = myLinks.length-1; i >= 0 ; i--) {
var myLink = myLinks[i];
var myFile = new File(myLink.filePath);
var myNewName = myLink.name.replace("20283", "21483");
if (myFile.exists) {
myFile.rename(myNewName);
myLink.relink(myFile);
myLink.update();
}
}
#target indesign
if (app.documents.length == 0) {
err("No documents are open. Please open a document and try again.");
}
if (app.activeDocument.links.length == 0) {
err("The current document contains no images. Please open a document containing images and try again.");
}
var myFind, myChange, myResult;
var myDoc = app.activeDocument;
var myLinks = myDoc.links;
var myDialog = app.dialogs.add({name:"Change job number", canCancel:true});
var myColumn = myDialog.dialogColumns.add();
var myPanel = myColumn.borderPanels.add();
var myLabel1 = myPanel.staticTexts.add({staticLabel:"Change "});
var myText1 = myPanel.textEditboxes.add();
if (app.extractLabel("kas_myText1") != "") {
myText1.editContents = app.extractLabel("kas_myText1");
}
var myLabel2 = myPanel.staticTexts.add({staticLabel:" to "});
var myText2 = myPanel.textEditboxes.add();
if (app.extractLabel("kas_myText2") != "") {
myText2.editContents = app.extractLabel("kas_myText2");
}
if(myDialog.show() == true){
var myFind = myText1.editContents;
var myChange = myText2.editContents;
app.insertLabel("kas_myText1", myFind);
app.insertLabel("kas_myText2", myChange);
for (i = myLinks.length-1; i >= 0 ; i--) {
var myLink = myLinks[i];
var myFile = new File(myLink.filePath);
var myNewName = myLink.name.replace(myFind, myChange);
if (myNewName != myLink.name) {
if (myFile.exists) {
myFile.rename(myNewName);
myLink.relink(myFile);
myLink.update();
}
}
}
myDialog.destroy();
alert("Done!");
}
else{
myDialog.destroy();
}
function err(e) {
alert(e);
exit();
}
#target indesign
if (app.documents.length == 0) {
err("No documents are open. Please open a document and try again.");
}
if (app.activeDocument.links.length == 0) {
err("The current document contains no images. Please open a document containing images and try again.");
}
var myFind, myChange, myResult;
var myFolder = Folder.selectDialog ("Choose a new job folder");
if (myFolder != null) {
var myDoc = app.activeDocument;
var myLinks = myDoc.links;
var myDialog = app.dialogs.add({name:"Change job number", canCancel:true});
var myColumn = myDialog.dialogColumns.add();
var myPanel = myColumn.borderPanels.add();
var myLabel1 = myPanel.staticTexts.add({staticLabel:"Change "});
var myText1 = myPanel.textEditboxes.add();
if (app.extractLabel("kas_myText1") != "") {
myText1.editContents = app.extractLabel("kas_myText1");
}
var myLabel2 = myPanel.staticTexts.add({staticLabel:" to "});
var myText2 = myPanel.textEditboxes.add();
if (app.extractLabel("kas_myText2") != "") {
myText2.editContents = app.extractLabel("kas_myText2");
}
if(myDialog.show() == true){
var myFind = myText1.editContents;
var myChange = myText2.editContents;
app.insertLabel("kas_myText1", myFind);
app.insertLabel("kas_myText2", myChange);
for (i = myLinks.length-1; i >= 0 ; i--) {
var myLink = myLinks[i];
var myFile = new File(myLink.filePath);
var myNewName = myLink.name.replace(myFind, myChange);
var myNewFile = new File(myFolder + "/" + myNewName);
if (myFile!= myNewFile) {
if (myFile.exists) {
myFile.copy(myNewFile);
myLink.relink(myNewFile);
myLink.update();
}
}
}
myDialog.destroy();
alert("Done!");
}
else{
myDialog.destroy();
}
}
function err(e) {
alert(e);
exit();
}
I agree, this is a very awesome script!
I use a slight variation of it. We have up to a couple hundred images on an indesign document. All the image files end in AA (" AA.tif" or " AA.eps"). Then we use this script to relink to the white plate file (all ending with " WT.tif") for each image. Some of the images do not contain white. The script works great, all the images that do not have white just leave the original front image in palce (the one that contains AA) Is there an easy way to script the removal of all the AA links? I don't want the file deleted or anything, i just need the link removed from the indesign document, so an empty box should remain where the AA file was. Right now we just manually delete these images, which is sometimes time consuming. I've looked around for ways to remove/unlink files but can't grasp how to make anything work.
//DESCRIPTION: Replace files ending in AA.tif or AA.eps that are linked images with their matching file ending with wt.tif alternates
/*
Front images have " AA" in their names; White plates have " WT.tif"
*/
myDoc = app.activeDocument;
myLinks = myDoc.links;
myFrontLayerName = "Front Colorbar";
myWhiteLayerName = "White Blackbar";
myBoxesLayerName = "boxes";
app.activeDocument.layers.item(myFrontLayerName).visible = false;
app.activeDocument.layers.item(myWhiteLayerName).visible = true;
app.activeDocument.layers.item(myBoxesLayerName).visible = false;
for (j = myLinks.length - 1; j >= 0; j--) {
myName = myLinks[j].filePath;
myNewName = myName.split(" AA.eps").join(" wt.tif");
if (myName != myNewName) {
// Original link includes " AA.eps" in name
myNewImageFile = File(myNewName);
if (!myNewImageFile.exists) {
continue;
}
myLinks[j].relink(myNewImageFile);
myLinks[j].update();
}
}
for (j = myLinks.length - 1; j >= 0; j--) {
myName = myLinks[j].filePath;
myNewName = myName.split(" AA.tif").join(" wt.tif");
if (myName != myNewName) {
// Original link includes " AA.tif" in name
myNewImageFile = File(myNewName);
if (!myNewImageFile.exists) {
continue;
}
myLinks[j].relink(myNewImageFile);
myLinks[j].update();
}
}
Just tried the script for renumbering files but I could not get it to work for our situation. We have files where we have to ad a prefix to all the image files, for example the file maybe called graphA.eps and we have to rename it ES_graphA.eps (ES refers to the language, Spanish in this case but it could be any language) and still remain linked. I have just had to do this over 200 times on the last job and we have 3 more. Can the Kasyans script be altered to insert a prefix as opposed to replacing one?
I don't know javascript at all! Try replying directly to one of the posts by Kasyan because they are a genius. In the meantime would something like this work?
Kasyans script uses this for replacing the old number in the filename to the new number:
var myNewName = myLink.name.replace("20283", "21483");
can you do something like this?
var myNewName = myLink.name.replace("graph", "ES_graph");
I have no idea if the number or characters has to match??
MKPETZ wrote:
can you do something like this?
var myNewName = myLink.name.replace("graph", "ES_graph");
I have no idea if the number or characters has to match??
No, it does not. This is a simple search-and-replace -- the first string is found in the variable on which the 'replace' command is performed (in this case, myLink.name) and only when it's found it is replaced by the second string. (That *does* logically mean that if your first string "graph" does not occur in the name, this command will do *nothing*. But I think it's safe to 'relink' an image with itself again.)
Thanks for the response to this MKPETZ and Jongware
Can this script be altered for this to work. Just to add a language prefix to all linked files.
Or can it be done another way. So if we start with all linked files which have been translated and then a run a script to add the language prefix and relink at the same time.
LouisHectorMonty2 wrote:
Can this script be altered for this to work. Just to add a language prefix to all linked files.
That would be as easy as this:
var myNewName = "ES_"+myLink.name;
-- where "ES_" is your language prefix. Just to make sure, this line should be changed in Kasyan's very first script in post #1.
Hi Jongware
Thanks that worked great, infact too great! I just ran it and realised I had changed all the files which had been translated and of course all the graphics that hadn't such as photgraphs etc. Is there a line that could be put in that would only change those with a mod date of today?
LouisHectorMonty2 wrote:
Is there a line that could be put in that would only change those with a mod date of today?
I think that's a bit too specific ...
So you have files with this prefix "ES_" that you did not translate (yet)? Hmmm ... easiest way out would be to delete, move, or rename them ... That makes sense as well, because if that prefix means you translated the text, these files shouldn't have one.
North America
Europe, Middle East and Africa
Asia Pacific