Copy link to clipboard
Copied
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.
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 = indd
Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
); var theDoc = app.activeDocument;
var allLinkNames =theDoc.links.everyItem().name;
for(var i = 0; i < toSearch.length; i++)
{
var myName = toSearch;
for(var s = 0; s < allLinkNames.length; s++)
{
var linkName = allLinkNames
;if (linkName === myName){
var newFile = File(myFolder + toRelink);
theDoc.links
.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
Copy link to clipboard
Copied
Simply amazing! I edited it to use my specific paths and file names and it works like a dream; it's pretty quick too.
How difficult would it be to add in commands for "Fit Content Proportionally" and "Center Content" that only alter the frames of the re-linked eps files?
Copy link to clipboard
Copied
Hallo UpdateRequired,
fine that it works
UpdateRequired wrote:
How difficult would it be to add in commands for "Fit Content Proportionally" and "Center Content" that only alter the frames of the re-linked eps files?
Not difficult at all.
Hans-Gerd Claßen
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@UpdateRequired – just a hint:
find out what the "parent" object of a specific link is.
And the "parent" of that "parent"…
app.activeDocument.links[0].parent;
app.activeDocument.links[0].parent.parent;
Uwe
Copy link to clipboard
Copied
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);
theDoc.links.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
Copy link to clipboard
Copied
-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...
Copy link to clipboard
Copied
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
); var theDoc = app.activeDocument;
var allLinkNames =theDoc.links.everyItem().name;
for(var i = 0; i < toSearch.length; i++)
{
var myName = toSearch;
for(var s = 0; s < allLinkNames.length; s++)
{
var linkName = allLinkNames
;if (linkName === myName){
var newFile = File(myFolder + toRelink);
with(theDoc.links
){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
Copy link to clipboard
Copied
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 .
Copy link to clipboard
Copied
Hi;
I tried the code. But the code says it can not find the logo file. But on the desktop with the same name and logos in a file that I created. What I missed?
Copy link to clipboard
Copied
code I modified it to be applicable to my path and image names.
But the code says it can not find the logo file. help please
indesign CC 2017 win / mac os
Copy link to clipboard
Copied
idjev wrote:
…But the code says it can not find the logo file…
We need more information to answer this.
Are there any special characters in your file names?
Is the folder of the logo stored on a network volume connected?
Is the volume connected in the moment you run that script?
Also: Maybe something's wrong with your folder path definition?
Place the logo from the path on a page and try to find the folder string.
Select the graphic frame holding the logo and run the following script snippet:
var graphic = app.selection[0].graphics[0];
var file = File(graphic.itemLink.filePath);
$.writeln(file.parent);
The file's parent is the folder where the placed logo is stored.
And the $.writeln() is writing its path to the JavaScript Console of the ESTK.
Test this snippet with your Mac and your Windows version of InDesign.
There might be a difference in the path discription.
Regards,
Uwe
Copy link to clipboard
Copied
Note:
in the meanwhile idjev sent me a PM with a link to his implementation of the script by Hans.
Hi idjev,
note that paths used with ExtendScript—also on Windows—should not use backslashes, but slashes to get the right folder:
Do not do a backslash:
var myFolder = 'C:\myFolderName';
Instead do a slash:
var myFolder = 'C:/myFolderName';
( Obviously you did not follow my advice in my last post and test the path on a placed and selected graphic. )
Regards,
Uwe
Copy link to clipboard
Copied
God bless you ... thank you so much
Copy link to clipboard
Copied
-hans-
I know it's years later. But your reply script saved me (and others at my work) countless hours worth of work. I modified it to be applicable to my path and image names. Boom! Far less work for me. Thank you, thank you, thank you! You're awesome!
Copy link to clipboard
Copied
Many Thanks Hans!