Thread View: adobe.scripting.indesign
11 messages
11 total messages
Started by carly7
Wed, 28 Jan 2009 13:44
Rename and relink images - Indesign CS4 - OSX10.5
Author: carly7
Date: Wed, 28 Jan 2009 13:44
Date: Wed, 28 Jan 2009 13:44
17 lines
1181 bytes
1181 bytes
Hi all I am looking for a script which will relink images that have changed part of their file name. OR a script which will rename AND relink if this is easier. At the moment I am using Automator to batch rename. For instance, I have the following files: 20283 GN6E451.tif 20283 56529823.eps 20283 571589.eps I want to change them so they are: 21483 GN6E451.tif 21483 56529823.eps 21483 571589.eps So only the first part of the file names change (this is a job number). And then be able to tell InDesign that these are the same files. Is there a script available to do this? Many thanks in advance!
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: Kasyan_Servetsky
Date: Wed, 28 Jan 2009 15:20
Date: Wed, 28 Jan 2009 15:20
17 lines
1002 bytes
1002 bytes
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();
}
}
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: carly7
Date: Wed, 28 Jan 2009 16:02
Date: Wed, 28 Jan 2009 16:02
1 lines
907 bytes
907 bytes
Thanks Kasyan, though I should have mentioned the 5 digit job number was an example only...both numbers would constantly be changing. I need a script where I could type the numbers into the script panel in InDesign itself...not the raw script. Is this possible?
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: Kasyan_Servetsky
Date: Wed, 28 Jan 2009 16:34
Date: Wed, 28 Jan 2009 16:34
1 lines
635 bytes
635 bytes
Yes, I'm writing a new version.
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: Kasyan_Servetsky
Date: Wed, 28 Jan 2009 16:54
Date: Wed, 28 Jan 2009 16:54
57 lines
2259 bytes
2259 bytes
#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 (myFile.exists) {
myFile.rename(myNewName);
myLink.relink(myFile);
myLink.update();
}
}
myDialog.destroy();
alert("Done!");
}
else{
myDialog.destroy();
}
function err(e) {
alert(e);
exit();
}
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: Kasyan_Servetsky
Date: Wed, 28 Jan 2009 16:58
Date: Wed, 28 Jan 2009 16:58
1 lines
681 bytes
681 bytes
P.S. I haven't tested this, so use carefully.
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: carly7
Date: Thu, 29 Jan 2009 10:03
Date: Thu, 29 Jan 2009 10:03
4 lines
738 bytes
738 bytes
No luck with this one, I get the following error: Error Number -2741 Expected expression property or key form, etc. but found unknown token.
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: Kasyan_Servetsky
Date: Thu, 29 Jan 2009 10:52
Date: Thu, 29 Jan 2009 10:52
4 lines
1008 bytes
1008 bytes
I tested the script in CS3 on Mac and PC and CS4 on Mac, using a simple document, which contains 3 links, named as in your 1st post. And it works for me. Possible solutions: * Send me a screenshot of the error message or run the script in ESTK and see which line it stops and error message it generates. * Send me an archived copy of your document to recreate the error.
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: carly7
Date: Thu, 29 Jan 2009 12:02
Date: Thu, 29 Jan 2009 12:02
7 lines
1251 bytes
1251 bytes
Sorry my scripting knowledge is a little limited, I had originally saved it as an applescript file. I've now saved through ESTK as a jsx file and it works perfectly! Thank you so much! On a side thought which I hadn't even considered before, is it at all possible to first copy the files from the original job folder into the new job folder, and then rename and relink? So if I ran the script and it prompted me to select a new destination folder to copy to, and then prompted for the rename info? I could simply copy and paste manually though it is often the case that the new job doesn't always use all of the images from the old job. thanks! :D
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: Kasyan_Servetsky
Date: Thu, 29 Jan 2009 13:52
Date: Thu, 29 Jan 2009 13:52
62 lines
2586 bytes
2586 bytes
#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();
}
Re: Rename and relink images - Indesign CS4 - OSX10.5
Author: carly7
Date: Thu, 29 Jan 2009 14:36
Date: Thu, 29 Jan 2009 14:36
1 lines
662 bytes
662 bytes
PERFECT! Thank you so much for your help I really appreciate it!! :D
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads