• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Batch renaming and relinking in InDesign CS4

New Here ,
Feb 25, 2010 Feb 25, 2010

Copy link to clipboard

Copied

Is there a plug-in available for InDesign that will batch rename and relink placed images?

In Quark, I used Badia Link Renamer which worked perfectly but it's not available for InDesign. (Was told they hope to have it incorporated into BigPicture for CS5.)

Is there something similar currently available for InDesign?

Essentially I need it to rename and relink files with random names to structured names such as:

001_Cust_000123456789_art_r1.tif

(I love that Bridge does batch renaming but then I have to manually update links in InDesign which is extremely time-consuming. I've also manually renamed/relinked files individually with Adobe Dialogue but it doesn't seem to be part of CS4.)

Any help or suggestions would be greatly appreciated! Been looking for something for months.

Thanks!

TOPICS
Scripting

Views

13.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2010 Feb 26, 2010

Copy link to clipboard

Copied

Some scripting going on here by Olav Kvern, a scripting master, in my book

http://avondale.typepad.com/indesignupdate/2005/09/renamerelink_sc.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 27, 2010 Feb 27, 2010

Copy link to clipboard

Copied

I made a couple of scripts that are quite close to what you want:

http://forums.adobe.com/message/2517344#2517344

http://forums.adobe.com/message/1110103#1110103

If you are interested, please make sure to read the threads before running the scripts.

Kasyan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 14, 2010 Apr 14, 2010

Copy link to clipboard

Copied

Thanks so much for these suggestions. I've read through the posts (and more) and I have something that's almost workable.

I've pasted it below. Is it possible to modify this to:

1. use sequential file numbers (001, 002, 003 etc) throughout the document rather than the current page number references

Generally I need all files to be named:  name_file number_r1.ext

2. update multiple instances of the same file? Currently it gives an error when trying to rename the second instance of a file that's already been renamed.

Thanks for any help you can give.

var myDoc = app.activeDocument;
var myAllLinks = myDoc.allGraphics;
var myPrepend = prompt("Example: thebook_08765", "Job description", "Please enter job description");
var response = confirm("Warning: You are about to rename all images linked to the foremost Indesign Document - proceed? Keep in mind - it is not reversible!");

if ( response == true )
{
    for ( k = 0; k < myAllLinks.length; k++ )
    {
        var myLinkName = myAllLinks.itemLink.name;
    }

    crearLabels();

    var myPages = myDoc.pages;

    for ( p = 0; p < myPages.length; p++ )
    {
        var myPageNumber = myPages

.name;

        var myLinks = myPages

.allGraphics;
        var myASCII = 97;
        for ( k = myLinks.length - 1; k >= 0; k-- )
        {
            var myLink = myLinks.itemLink;
            if (myLink.extractLabel("relinked") != "yes") {
                var myOldLinkName = myLink.name;
                var myLinkUsage = LinkUsage( myLink );
                var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                if (myLinkUsage == 1)
                {
                    var myNewLinkName = myPrepend + '_p' + myPageNumber + String.fromCharCode( myASCII ) + '_r1' + myExtension;
                    var myOldImageHDfile = new File( myLink.filePath );
                    myOldImageHDfile.rename( myNewLinkName );
                    myLink.insertLabel("relinked", "yes");
                    myLink.relink( myOldImageHDfile );
                    try {
                        myLink = myLink.update();
                    }
                    catch(err) {}
                    myASCII++;
                }
                else
                {
                    processMultiUsedLinks(myLink);
                }
            }
        }
    }

    var myMasterSpreads = myDoc.masterSpreads;
   
    for ( m = 0; m < myMasterSpreads.length; m++ )
    {
        var myMastSpr = myMasterSpreads;
        var myPageNumber = myMastSpr.name;
        var myPrefix = myMastSpr.namePrefix;
        var myLinks = myMastSpr.allGraphics;
        var myASCII = 97;
        for ( n = myLinks.length - 1; n >= 0; n-- )
        {
            var myLink = myLinks.itemLink;
            if (myLink.extractLabel("relinked") != "yes") {
                var myOldLinkName = myLink.name;
                var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                var myLinkLetter = (myLinks.length == 1) ? "" : String.fromCharCode( myASCII );
                var myNewLinkName = myPrepend + '_master_' + myPrefix + myLinkLetter + myExtension;
                var myOldImageHDfile = new File( myLink.filePath );
                myOldImageHDfile.rename( myNewLinkName );
                myLink.insertLabel("relinked", "yes");
                myLink.relink( myOldImageHDfile );
                try {
                    myLink.update();
                }
                catch(err) {}
                myASCII++;
            }
        }
    }
}

//------------------------- Functions -------------------------------------
// Check how many times the link was placed
function LinkUsage(myLink) {
    var myLinkCounter = 0;
        for (var c =  0; c < myDoc.links.length; c++) {
        if (myLink.filePath == myDoc.links.filePath) {
            myLinkCounter += 1;
        }
    }
    return myLinkCounter
}
// Relink the links placed more than once
function processMultiUsedLinks(myLink) {
    var myMultiUsedLink = new Array();
    var myPagesArr = new Array();
    var myAllLinks = myDoc.links;
    for (var d = 0; d < myAllLinks.length; d++)  {
        if (myAllLinks.filePath == myLink.filePath) {
            myMultiUsedLink.push(myAllLinks);
        }
    }
    for (e = myMultiUsedLink.length-1; e >= 0 ; e--) {
        myPagesArr.push(myMultiUsedLink.parent.parent.parent.name);
    }
    var myPageNames = myPagesArr.sort().join("_");
    var myNewLinkName = myPrepend + '_p' + myPageNames + myExtension;
    var myOldImageHDfile = new File( myLink.filePath );
    myOldImageHDfile.rename( myNewLinkName );
    myLink.insertLabel("relinked", "yes");
    myLink.relink( myOldImageHDfile );
    try {
        myLink = myLink.update();
    }
    catch(err) {}

    for (f = myMultiUsedLink.length-2; f >= 0 ; f--)
    {
        var myCurrLink = myMultiUsedLink;
        myCurrLink.insertLabel("relinked", "yes");
        myCurrLink.relink( myOldImageHDfile );

        try {
            myCurrLink = myLink.update();
        }
        catch(err) {}
    }
    UpdateAllOutdatedLinks();
}
// Clear labels in case this script has been already run on the current document
function crearLabels() {
    for (var f =  0; f < myDoc.links.length; f++) {
        if (myDoc.links.extractLabel("relinked") != "") {
            myDoc.links.insertLabel("relinked", "");
        }
    }
}
//--------------------------------------------------------------------------------------------------------------
function UpdateAllOutdatedLinks() {
    for(var myCounter = myDoc.links.length-1; myCounter >= 0; myCounter--){
        var myLink = myDoc.links[myCounter];
        if (myLink.status == LinkStatus.linkOutOfDate){
            myLink.update();
        }
    }
}
//--------------------------------------------------------------------------------------------------------------
function pad000(myNumber) {
    if (myNumber >= 1 && myNumber <= 9) {
        x =  "0" + "0" + myNumber;
    } else if (myNumber >= 10 && myNumber <= 99) {
        x = "0" + myNumber;
    } else if (myNumber >= 100 && myNumber <= 999) {
        x = myNumber;
    }
    return x;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 14, 2010 Apr 14, 2010

Copy link to clipboard

Copied

Here is my last version of the script, it deals with multiple instances of the same file.

Kasyan

var myDoc = app.activeDocument;
var myAllLinks = myDoc.allGraphics;
var myMultipleLinks = new Array();
var myLinksCounter = 1;
var myPrepend = prompt("Example: thebook_08765", "Job description", "Please enter job description");
if (!myPrepend) exit();
var response = confirm("Warning: You are about to rename all images linked to the foremost Indesign Document - proceed? Keep in mind - it is not reversible!", false, "Rename Links Script");

if ( response == true )
{
     WriteToFile("\r--------------------- Script started -- " + GetDate() + " ---------------------\n\n");
     
     for ( k = 0; k < myAllLinks.length; k++ )
     {
          var myLinkName = myAllLinks.itemLink.name;
     }

     crearLabels();

     var myPages = myDoc.pages;
     // Pages
     for ( p = 0; p < myPages.length; p++ )
     {
          var myPageNumber = pad000(myPages

.name);

          var myLinks = myPages

.allGraphics;
          var myASCII = 97;
          for ( k = myLinks.length - 1; k >= 0; k-- )
          {
               var myLink = myLinks.itemLink;
               if (myLink.extractLabel("relinked") != "yes") {
                    var myOldLinkName = myLink.name;
                    var myLinkUsage = LinkUsage( myLink );
                    var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                    if (LinkUsage(myLink) == 1)
                    {
                         var myNewLinkName = myPrepend + myPageNumber + String.fromCharCode( myASCII ) + myExtension;
                         var myOldImageHDfile = new File( myLink.filePath );
                         var myRenameResult = myOldImageHDfile.rename( myNewLinkName );
                         if (myRenameResult)     {
                              myLink.insertLabel("relinked", "yes");
                              myLink.relink( myOldImageHDfile );
                              try {
                                   myLink = myLink.update();
                              }
                              catch(err) {}
                              myASCII++;
                              WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");
                              myLinksCounter++;
                         }
                         else {
                              if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {
                                   WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + " because the file already exists\n");
                              }
                              else {
                                   WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");
                              }
                         }
                    }
                    else {
                         if (!IsObjInArray(myLink, myMultipleLinks)) {
                              myMultipleLinks.push(myLink);
                         }
                    }
               }
          }
     }

     var myMasterSpreads = myDoc.masterSpreads;
     // Master spreads
     for ( m = 0; m < myMasterSpreads.length; m++ )
     {
          var myMastSpr = myMasterSpreads;
          var myPageNumber = myMastSpr.name;
          var myPrefix = myMastSpr.namePrefix;
          var myLinks = myMastSpr.allGraphics;
          var myASCII = 97;
          for ( n = myLinks.length - 1; n >= 0; n-- )
          {
               var myLink = myLinks.itemLink;
               if (myLink.extractLabel("relinked") != "yes") {
                    var myOldLinkName = myLink.name;
                    var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
                    if (LinkUsage(myLink) == 1)
                    {
                         var myLinkLetter = (myLinks.length == 1) ? "" : String.fromCharCode( myASCII );
                         var myNewLinkName = myPrepend + '_master_' + myPrefix + myLinkLetter + myExtension;
                         var myOldImageHDfile = new File( myLink.filePath );
                         var myRenameResult = myOldImageHDfile.rename( myNewLinkName );
                         if (myRenameResult) {
                              myLink.insertLabel("relinked", "yes");
                              myLink.relink( myOldImageHDfile );
                              try {
                                   myLink.update();
                              }
                              catch(err) {}
                              myASCII++;
                              WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");
                              myLinksCounter++;
                         }
                         else     {
                              if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {
                                   WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + " because the file already exists\n");
                              }
                              else {
                                   WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");
                              }
                         }
                    }
                    else
                    {
                         if (!IsObjInArray(myLink, myMultipleLinks)) {
                              myMultipleLinks.push(myLink);
                         }
                    }
               }
          }
     }
     // Multiple images
     if (myMultipleLinks.length > 0) {
          for ( a = myMultipleLinks.length - 1; a >= 0; a-- )
          {
               processMultiUsedLinks(myMultipleLinks);
          }
     }

     WriteToFile("\r--------------------- Script finished -- " + GetDate() + " --...




























































































































































Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 17, 2015 May 17, 2015

Copy link to clipboard

Copied

Same link on multiple pages in document...Anyone can modify script from post #5, 14 april, to rename only first instance of this link to "prefix_page number" and simply use this link in all other instances?

example:

picture.jpg is on page 1, 2 and 3. I want to be prefix_00(1)a.jpg and to be linked to all other instances.

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 18, 2015 May 18, 2015

Copy link to clipboard

Copied

Here is a more recent version of the script.

For a link placed multiple times it asks user for a new name.

18-05-2015 10-54-57.jpg

And renames all the instances.

18-05-2015 10-55-16.jpg

Regards,
Kasyan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

F.Y.I. your batch and relink InDesign script still works as advertised running Adobe InDesign CC 17 12.0.0.81

THANK YOU THIS IS A LIFESAVER SCRIPT

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 14, 2010 Apr 14, 2010

Copy link to clipboard

Copied

Thanks again, Kasyan, for your help.

Is it possible to not have it pop up with a custom name box when there are multiple files with the same name, but to just name it automatically?

Also, is it possible to number files sequentially throughout the document rather than as page references?

I figured out how to add in "_r1" to the end of the file name in the previous version of the script, but I can't figure out where it would go in this version.

(I clearly need to work on my next to nil scripting skills.)

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 14, 2010 Apr 14, 2010

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 14, 2010 Apr 14, 2010

Copy link to clipboard

Copied

Yes, everything is possible with scripting — almost everything. However, I am terribly busy these days and have no time to remake the script to your needs.

Regards,

Kasyan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 21, 2010 Apr 21, 2010

Copy link to clipboard

Copied

Many thanks Kasyan for updating this script, it works flawlessly with minor changes to suite our usage.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2010 Apr 15, 2010

Copy link to clipboard

Copied

Sorry, Kasyan, did not meant to imply that you weren't busy, and I very much appreciate the help.

Would you mind recommending someone who may be interested in doing the modifications on a freelance basis?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 04, 2010 May 04, 2010

Copy link to clipboard

Copied

TO_BookMaker: Did you ever resolve this to fit your precise specifications? I have the exact same needs. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 11, 2010 May 11, 2010

Copy link to clipboard

Copied

I'd like to amend my last post to say TO_Bookmaker, since we have the exact same needs, we probably work for the same company and I'd be happy to share development costs with you.

Kasyan, I really like the way you mark up your scripts with comments. It's really helpful for anyone trying to learn. Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 31, 2013 Jan 31, 2013

Copy link to clipboard

Copied

Sorry for bumping this old post, but does anybody know how to adapt Kasyan's script to work with multiple documents in a book? It's fantastic for single documents, but doesn't work for other docs that share the same links.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 31, 2013 Jan 31, 2013

Copy link to clipboard

Copied

I'll try to rework it when time permits --  maybe next week.

Regards,

Kasyan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 31, 2013 Jan 31, 2013

Copy link to clipboard

Copied

Thanks, Kasyan!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 04, 2013 Feb 04, 2013

Copy link to clipboard

Copied

I totally reworked my Update path names in links script: now it can batch process multiple documents. I also added some new features: logging, making backups, an option to relink only missing links.

I'd like to get any feedback on the script.

Regards,
Kasyan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2013 Feb 04, 2013

Copy link to clipboard

Copied

This new version worked great for me (Indesign CS6 on a Mac OS X 10.7.5). I received an error message when I tested it with CS5 documents in CS6, so I assume that the documents must be converted before running the script.

http://cl.ly/image/373z0I09473z

Is there a way to also rename the links in the process, just like the original script in this page? Or maybe replace spaces and special characters in file names? It would be really useful to be able to rename links for multiple documents in a batch for later ePUB exporting. The problem is that Indesign maintains spaces and special characters in file names, which can cause the ePUB to fail to validate.

Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 04, 2013 Feb 04, 2013

Copy link to clipboard

Copied

I received an error message when I tested it with CS5 documents in CS6, so I assume that the documents must be converted before running the script.

With Resave files script you can "upgrade" documents created in older versions of InDesign. There are two slightly different versions of the script. One of them (I don't remember which exactly) does this, another doesn't.

Is there a way to also rename the links in the process, just like the original script in this page?

Both versions -- 15.0 and 14.1 -- don't rename any links. They just look for image files either with the same name, or the same base name, but different extension.

Or maybe replace spaces and special characters in file names?

I made a script which renames links replacing Cyrillic characters with Latin equivalents (it's called transliteration) and relinks all the instances (a link can be placed many times) of renamed links. I am going to make and post a version which removes accented and special (don't have idea which exactly at the moment) characters from the links.

It would be really useful to be able to rename links for multiple documents in a batch for later ePUB exporting.

A while ago I wrote a script for my client according to some specific requirements. I am going to rework it and make a version for general usage. The idea is to rename all the links (and maybe also the documents) according to a scheme: e.g. isbn-number + consecutive number, or prefix + base name + suffix

or [prefix] + base name + [suffix] + page number + consecutive number. (Possible variants are unlimited).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2013 Feb 04, 2013

Copy link to clipboard

Copied

I am going to make and post a version which removes accented and special (don't have idea which exactly at the moment) characters from the links.

"Web-friendly" Indesign links! This is going to be extremely useful when using Indesign to deliver ePUB/HTML. There are cases where we must maintain the original file names, just removing special characters/spaces.

A while ago I wrote a script for my client according to some specific requirements. I am going to rework it and make a version for general usage. The idea is to rename all the links (and maybe also the documents) according to a scheme: e.g. isbn-number + consecutive number, or prefix + base name + suffix

or [prefix] + base name + [suffix] + page number + consecutive number.

This covers everything else. Kudos for you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 23, 2014 Nov 23, 2014

Copy link to clipboard

Copied

Hi,

I am packaging the documents folders like 1. Text1, 2. Text2, 3. Text3, ... etc. Everything in  one folder Text  ..nddi, .eps, .pdf the problem is some links used in  over and text are the same name. I want to keep both links with added suffix "_1, _2..........._165" and updated in indd.

Please help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2023 Feb 05, 2023

Copy link to clipboard

Copied

LATEST

"A while ago I wrote a script for my client according to some specific requirements. I am going to rework it and make a version for general usage. The idea is to rename all the links (and maybe also the documents) according to a scheme: e.g. isbn-number + consecutive number, or prefix + base name + suffix

or [prefix] + base name + [suffix] + page number + consecutive number. (Possible variants are unlimited)."

 

I am trying to do something extremely similar, in the format: consecutive number + base name + isbn + art_r1

 

Would you be willing to share the script again. I believe I could alter it to accomplish what I need. (The link above is no longer active.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2015 May 19, 2015

Copy link to clipboard

Copied

he Kasyan

Just some 5c about this great script.

1. This work, but...In my workflow we sometimes have many many duplicated links across doc (formulas in mathematical layout), so manually typing name is time consuming and produce non-uniform names. Look at this example from your zip file. When ask for name I simply write some page number. But If need to write this for example 100 duplicated links this can be nightmare. What I will recommend is that script rename only first instance duplicated link by first page where is and link this to other instances???

2. Because your script write txt report here is list for undo command.

3. I think that better path for report.txt will be in indd folder.

screenshot_01 copy.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines