Skip navigation
Currently Being Moderated

Scripting Specific Link Replacement

Sep 10, 2012 4:52 PM

Tags: #cs5 #relink #javascript #indesign #scripting #automation #relinking

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.

 
Replies
  • Currently Being Moderated
    Sep 10, 2012 5:31 PM   in reply to UpdateRequired

    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.)

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2012 9:25 AM   in reply to UpdateRequired

    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
    
     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2012 11:26 AM   in reply to UpdateRequired

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 15, 2012 12:58 AM   in reply to UpdateRequired

    @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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 15, 2012 1:46 AM   in reply to UpdateRequired

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 16, 2012 1:40 AM   in reply to -hans-

    -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...

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 16, 2012 2:43 AM   in reply to UpdateRequired

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points