Our company is undergoing a name/logo change and we have around 1000-1500 indesign documents that need to have logo links replaced/re-linked.
I need some help creating a script, preferably using javascript, that will allow me to relink around 10 different logo files to completely different paths with completely different file names. All of the files are on a windows based server, and all of our indesign users are windows cs5.0 based as well. I would like the script to loop through a set of specific logo links and have it replace any and all instances of old logos with the new logos.
Example
K:\poor\directory\structure\sadface\RedCoLogo_White.eps becomes L:\CompanyLogos\BlueIncLogo_W.eps
K:\poor\directory\structure\sadface\RedCoLogo_Black.eps becomes L:\CompanyLogos\BlueIncLogo_B.eps
K:\poor\directory\structure\sadface\RedCoLogo_Red.eps becomes L:\CompanyLogos\BlueIncLogo_R.eps
K:\poor\directory\structure\sadface\RedCoLogo_Green.eps becomes L:\CompanyLogos\BlueIncLogo_G.eps
I have already tried some premade scripts that use dialogue boxes to input the old path and new path, but I need the script to run without user interaction so it can batch run it using another script I found that will open the indesign files in a given directory, run a script, save and close.
I do not know javascript very well, but I am fimiliar with how it works and its syntax/etc; I have already customized a handfull of FindChangeByList scripts to use different txt files and loop through a specific number of active indesign files.
Any help would be greatly appreciated.
There are several scripts at:
http://www.kasyan.ho.com.ua/my_scripts.html
which may be applicable to your situation.
(Let me know privately if you want help in adapting one of them.)
I have tried/tinkered with all of the sctipts on kasyan's page already. The one that closest matches my needs is http://www.kasyan.ho.com.ua/restore_paths_of_links.html since it works with absolute file paths including the file name. However it requires user interaction and will only do one file at a time (no different than just relinking via the links pallete).
I can comment out the dialogue box and confirmation screens easily to run unattended, but since the dialogue box is used to write the paths to a magic file on the desktop, I cannot figure out how to hard code the old/new path(s) into the script.
Hi,
minor error handling. just basically tested. You may try it.
#target InDesign
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT
app.activate();
var myFolder = 'L:/CompanyLogos/';
var toSearch = ['RedCoLogo_White.eps', 'RedCoLogo_Black.eps', 'RedCoLogo_Red.eps', 'RedCoLogo_Green.eps'];
var toRelink = ['BlueIncLogo_W.eps', 'BlueIncLogo_B.eps', 'BlueIncLogo_R.eps', 'BlueIncLogo_G.eps'];
var inddFiles = Folder.selectDialog ('Please choose folder with *.indd-files').getFiles('*.indd');
var l = inddFiles.length;
while(l--){
try{
app.open(inddFiles[l]);
var theDoc = app.activeDocument;
var allLinkNames =theDoc.links.everyItem().name;
for(var i = 0; i < toSearch.length; i++)
{
var myName = toSearch[i];
for(var s = 0; s < allLinkNames.length; s++)
{
var linkName = allLinkNames[s];
if (linkName === myName){
var newFile = File(myFolder + toRelink[i]);
theDoc.links[s].relink(newFile);
}
}
}
theDoc.save();
theDoc.close();
}catch (e){
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
displayDialog(e);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
}
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
function displayDialog(aString){
var infoWindow = new Window("palette");
infoWindow.add("statictext", undefined, aString);
infoWindow.show();
$.sleep(1000);
infoWindow.close();
}
Hans-Gerd Claßen
Haha, that might be easy for you to say; I am not nearly as experienced with scripting as you are.
The closest commands I have found in searching so far for fit content to frame and centering are these:
app.activeDocument.rectangles.everyItem().fit(FitOptions.fillProportionally);app.activeDocument.rectangles.everyItem().fit(FitOptions.centerContent);
However, I'm not sure how to add them into the script you created, or how to have it only affect the logo files that are being relinked. I would guess that I need to create a variable and have it use the link names I define to apply fitting to; probably by replacing .everyItem(). I just don't know quite how to accomplish this.
Hello UpdateRequired,
Uwe gave you the right kick, so you may have the ability to solve it.
Here's the part that's important for your needs:
var newFile = File(myFolder + toRelink[i]);
theDoc.links[s].relink(newFile);
//get parent and apply the fit commands
Have to say it's all well-meant
just trying to follow the dos and don't
Have a sunny weekend ![]()
Hans-Gerd Claßen
-hans- wrote:
Have to say it's all well-meant
just trying to follow the
dos and don't
You can feel free to give the full answer. All I meant there was that the person asking shouldn't expect to get the full code written for them... ![]()
Hi,
I've added the the fit-options ....
#target InDesign
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT
app.activate();
var myFolder = 'L:/CompanyLogos/';
var toSearch = ['RedCoLogo_White.eps', 'RedCoLogo_Black.eps', 'RedCoLogo_Red.eps', 'RedCoLogo_Green.eps'];
var toRelink = ['BlueIncLogo_W.eps', 'BlueIncLogo_B.eps', 'BlueIncLogo_R.eps', 'BlueIncLogo_G.eps'];
var inddFiles = Folder.selectDialog ('Please choose folder with *.indd-files').getFiles('*.indd');
var l = inddFiles.length;
if (l === 0){displayDialog('The selcted folder doesn\'t contain ID-Files'); exit()};
while(l--){
try{
app.open(inddFiles[l]);
var theDoc = app.activeDocument;
var allLinkNames =theDoc.links.everyItem().name;
for(var i = 0; i < toSearch.length; i++)
{
var myName = toSearch[i];
for(var s = 0; s < allLinkNames.length; s++)
{
var linkName = allLinkNames[s];
if (linkName === myName){
var newFile = File(myFolder + toRelink[i]);
with(theDoc.links[s]){
relink(newFile);
parent.fit(FitOptions.fillProportionally);
parent.fit(FitOptions.centerContent);
}
}
}
}
theDoc.save();
theDoc.close();
}catch (e){
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
displayDialog(e);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
}
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
function displayDialog(aString){
var infoWindow = new Window("palette");
infoWindow.add("statictext", undefined, aString);
infoWindow.show();
$.sleep(2000);
infoWindow.close();
}
Hope it'll work ![]()
Thank you all so much. This is more help than I expected to get. I just had to modify FitOptions.fillProportionally to be FitOptions.proportionally to get the desired outcome; the results are smashing! I also have a slightly better grasp on js because of this undertaking.
I'll toast my next beer to Hans
.
North America
Europe, Middle East and Africa
Asia Pacific