27 Replies Latest reply on Jan 15, 2016 3:54 PM by chillbot75

    Renaming Artwork Automatically

    Bill Bernhardt

      I need to find a script that will rename the imported artwork files.

       

      I have many artwork files with different names, that I would like to rename to a project number, and then relink them into the document.

       

      I would first "package" the document to get the files into one common folder. Once the files are in one link folder, I would like to rename and link them to that project.

       

      The script must allow me to assign the base file name.

        • 1. Re: Renaming Artwork Automatically
          Kasyan Servetsky Level 5

          Hi Bill,

           

           

          Some time ago I wrote together with other guys such a script. There was a discussion on this subject: http://forums.adobe.com/message/1106014#1106014 — see post #62 and above.

           

          Warning! Use it with care and only on copies of your files — it renames linked images in the active indd file.

           

           

          Kasyan

          • 2. Re: Renaming Artwork Automatically
            Bill Bernhardt Level 1

            Kasyan,

             

            Thank you for the reply.

             

            I am a bit confused about the script or what portion I am to copy.

             

            Is there anyway you could e-mail the script?

             

            Bill.Bernhardt@doosan.com

             

            I would be vary greatful.

             

            Then a couple questions to be sure?

             

            It will allow me to add a beginning name of my choice? Like "WWAAU" folowed by #### - where # = a figure number. Next document uses "WWAAV" and so on.

             

            If I package the document and run the script it will then rename the files in the packaged book? Then I can recopy the files to my working directory. Thus your warning.

             

             

            • 3. Re: Renaming Artwork Automatically
              Kasyan Servetsky Level 5

              Hi Bill,

               

               

              Here is the script. It renames linked image files on page by page basis. At start a dialog  pops up asking you to enter a base name, then a confirmation dialog appears warning that all links in the current document are going to be renamed, and if you press Ok all links located on pages (not on master pages or pasteboard) are renamed like so :

              WWAAU_001_a.jpg, WWAAU_001_b.jpg, WWAAU_001_c.jpg and so on.

              Where: WWAAU — base name

              001 —the number of the page where the image is placed

              a, b, c … — numbering of images located on the same page

               

              If I package the document and run the script it will then rename the files in the packaged book?

               

              It depends on the Update Graphic Links In Package option: If It’s on — script will rename packaged copies, if not — original files (I assume that you run the script on the packaged document).

               

               

              Kasyan

              • 4. Re: Renaming Artwork Automatically
                amy_emcdesign

                Hi I have been trying to use your scripts as they sound perfect for what we want but

                I keep getting errors can anyone help me to get them running?

                 

                Thanks

                Amy

                • 5. Re: Renaming Artwork Automatically
                  John Hawkinson Level 5

                  Hi, Amy.

                   

                  You have to help us help you! Please tell us exactly what errors you get. Otherwise we're left guessing and that makes it really tough to assist.

                  • 6. Re: Renaming Artwork Automatically
                    amy_emcdesign Level 1

                    Hi John,

                     

                    Sorry I thought I'd put the feelers out in thread which were a bit cold before I went into too much depth!

                     

                    here is an example of an error:

                     

                    [img]http://img31.imageshack.us/img31/8218/myerror.jpg[/img]

                     

                    I have actually made my own thread, as we do have a working script which we've got some minor ish issues with.

                     

                    Amy

                    • 7. Re: Renaming Artwork Automatically
                      John Hawkinson Level 5

                      Umm...which script are you running that produces this error? It can't be Kasyan's

                      RenameLinksWithConfirm_DuncDude2.jsx.zip since that's only 54 lines long and doesn't include a variable called myPagesArr.

                       

                      More details are necessary.

                       

                      p.s.: you can include inline images by clicking the camera icon (3rd grouping), instead of an external attachment.

                      • 8. Re: Renaming Artwork Automatically
                        amy_emcdesign Level 1

                        oh ok thanks - I saw what I did didn't work, I'm not really very good on forums (or at anyhting it seems this week - my I am feeling sorry for myself!)

                         

                        I've tried the script in this thread:

                         

                        http://forums.adobe.com/thread/288979?tstart=0

                         

                        an also this one:

                         

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

                         

                        this second one literally does nothing at all on my computer, no error or anything - I'm a bit confused between JavaScript and AppleScript too which is making things worse - I really feel now this is beyond my brain to understand or fix!

                         

                        Amy

                        • 9. Re: Renaming Artwork Automatically
                          Kasyan Servetsky Level 5

                          Hi Amy,

                           

                          I amended the script so it works with ID 6.0.4 (this update has broken the way links are handled by script) and I also attached sample files to demonstrate how it works.

                           

                          The second script is for CS2 – try to place it inside "Scripts Panel > Version 4.0 Scripts" folder and run again

                           

                          Kasyan

                           

                          P.S. I don't see the attach file option any more, could you give me your e-mail so that I could send you the files

                          • 10. Re: Renaming Artwork Automatically
                            amy_emcdesign Level 1

                            Hi Kasyan

                             

                            I've put the scripts in the panel as you suggested and they seem to get a bit further along before producing errors now, bummer I actually thought they were running!

                             

                            I've sent you a pm wit my email, I really appreciate everyone's help this forum is brilliant!

                             

                            Amy

                             

                            edit: well i ran this one and still got an error - bit different this time, I'm think it's something I'm doing wrong?

                             

                            myerror2.jpg

                            • 11. Re: Renaming Artwork Automatically
                              Kasyan Servetsky Level 5

                              I meant that the 2nd script — written by Olav Kvern — should be placed inversion 4.0 scripts folder.

                              The one I sent you should be placed in Scripts Panel folder.

                              • 12. Re: Renaming Artwork Automatically
                                amy_emcdesign Level 1

                                Oh sorry, yes this runs now, it's not quite what we need but it's great to have some success!

                                 

                                unforunately we're not changing a job name, we're replacing any random file names which are inconsistent with one job number

                                 

                                i.e. they could be called

                                 

                                image1.tif

                                picture45a.psd

                                artwork004b.ai

                                 

                                etc

                                 

                                and we want to rename and remove the exisitng file names

                                 

                                to

                                 

                                JOBNAME001a.tif

                                JOBNAME001b.psd

                                JOBNAME002a.ai

                                 

                                it doesn't seem unachievable now, with a code I can actually see and work out how it's working!

                                • 13. Re: Renaming Artwork Automatically
                                  Kasyan Servetsky Level 5

                                  I remember that I wrote this script – it should be somewhere on the forum, I'll look for it in my archive and let you know if I find it.

                                  • 15. Re: Renaming Artwork Automatically
                                    Kasyan Servetsky Level 5

                                    There were several versions of the script — this one renames images placed on master pages as well.

                                    Who knows why attachment of files is unavailable any more?

                                     

                                    //====================================================

                                    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[k].itemLink.name;
                                        }

                                        crearLabels();

                                        var myPages = myDoc.pages;

                                        for ( p = 0; p < myPages.length; p++ )
                                        {
                                            var myPageNumber = pad000(myPages[p].name);

                                            var myLinks = myPages[p].allGraphics;
                                            var myASCII = 97;
                                            for ( k = myLinks.length - 1; k >= 0; k-- )
                                            {
                                                var myLink = myLinks[k].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 + myPageNumber + String.fromCharCode( myASCII ) + 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[m];
                                            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[n].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[c].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[d].filePath == myLink.filePath) {
                                                myMultiUsedLink.push(myAllLinks[d]);
                                            }
                                        }
                                        for (e = myMultiUsedLink.length-1; e >= 0 ; e--) {
                                            myPagesArr.push(myMultiUsedLink[e].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[f];
                                            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[f].extractLabel("relinked") != "") {
                                                myDoc.links[f].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;
                                    }

                                    • 16. Re: Renaming Artwork Automatically
                                      John Hawkinson Level 5

                                      File attachments are disabled because of a security problem; see the overview notice at the non-scripts forum. When you paste, could you use the Insert (>>) function with Syntax Highligting -> Java? It makes the code a lot easier to read.

                                       

                                      As a practical point, I think pasting it in is much much better anyhow. It means people actually READ your code, which is always good!

                                      • 17. Re: Renaming Artwork Automatically
                                        amy_emcdesign Level 1

                                        thanks for this, it's really really close...

                                         

                                        ...if anyone can help with what could be added to allow the script to offer manual insertion of a 'generic name for multiple images' when an image is placed more than once, it would be perfect for our requirements

                                         

                                        I've order myself a book on Javascript so I can begin to unpick and fathom out what on earth it all means!

                                         

                                        but this has really saved my nacon so thanks very much!

                                         

                                        Amy

                                        • 18. Re: Renaming Artwork Automatically
                                          Kasyan Servetsky Level 5

                                          Thank you, John.

                                           

                                          I'll certainly use Syntax Highligting — I used XML Highligting once but it removed quotation marks from my code, so I thought it would be more reliable to just attach scripts.

                                           

                                          Kasyan

                                          • 19. Re: Renaming Artwork Automatically
                                            John Hawkinson Level 5

                                            Sorry for the delay, I had meant to get to this a bit earlier.

                                            It's not helpful for you to post in multiple threads. I'll post a note in the other thread directing followups here, then maybe someone can lock it. Your request in the other thread makes no sense without this thread, since it's highly dependent on Kasyan's script.

                                             

                                            Here's a version of Kasyan's script that seems to solve your problem. This also fixes what seem to have been some bugs in Kasyan's pre-existing handling of multiply-linked images. Specifically the script seemed to get try to handle that case but get confused when it tried to relink a link it had already relinked. It think it was depending on the relinked image to be the last image in myMultiUsedLink, and perhaps that is not always  true.

                                             

                                            So anyhow, changes:

                                            1. Skip the loop if the link isn't valid. Multiply-linked links seem to invalidate the saved link reference when they are relinked.
                                            2. Add some debugging of mine. It's all conditionalized on if (debug), so it should do no harm and might be useful in the future.
                                            3. Prompt for a linkname tag if the image is multiply-linked. This is Amy's request. It's basically two lines 118-119.
                                            4. Don't loop from length-2 to 0, loop from length-1 to zero.
                                            5. Within the multiply-linked image loop, check the "relinked" label each time

                                             

                                            Amy, if this doesn't work for you, it would probably be best for you to make a sample document available. As simple as possible that still replicates the problem.

                                             

                                            // from http://forums.adobe.com/message/2632448#2632448
                                            // renameArtwork.jsx. Originally by Kasyan Servetsky.
                                            //====================================================
                                            
                                            var debug = 0;
                                            
                                            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[k].itemLink.name;
                                                }
                                            
                                                crearLabels();
                                            
                                                var myPages = myDoc.pages;
                                            
                                                for ( p = 0; p < myPages.length; p++ )
                                                {
                                                    var myPageNumber = pad000(myPages[p].name);
                                            
                                                    var myLinks = myPages[p].allGraphics;
                                                    var myASCII = 97;
                                                    for ( k = myLinks.length - 1; k >= 0; k-- )
                                                    {
                                                        if (!myLinks[k].isValid) continue;
                                                        var myLink = myLinks[k].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 + myPageNumber + String.fromCharCode( myASCII ) + myExtension;
                                                                var myOldImageHDfile = new File( myLink.filePath );
                                                                if (myOldImageHDfile.rename( myNewLinkName) != true) {
                                                                  if (debug) $.writeln("Failed to rename "+myLink.filePath+" to "+myNewLinkName);
                                                                    continue;
                                                                } else
                                                                  if (debug) $.writeln("renamed "+myLink.filePath+" to "+myNewLinkName+" see?:"+myOldImageHDfile.name);
                                                                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[m];
                                                    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[n].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[c].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[d].filePath == myLink.filePath) {
                                                        myMultiUsedLink.push(myAllLinks[d]);
                                                    }
                                                }
                                                for (e = myMultiUsedLink.length-1; e >= 0 ; e--) {
                                                    myPagesArr.push(myMultiUsedLink[e].parent.parent.parent.name);
                                                }
                                                var myPageNames = myPagesArr.sort().join("_");
                                                var thislinkname = prompt("Example: LISICON", "LISICON", "Image "+myLink.filePath+" is multiply-linked. Specify a tag.");
                                                var myNewLinkName = myPrepend + thislinkname + myExtension;
                                                var myOldImageHDfile = new File( myLink.filePath );
                                                                if (myOldImageHDfile.rename( myNewLinkName) != true) {
                                                                          if (debug) $.writeln("Failed to rename "+myLink.filePath+" to "+myNewLinkName);
                                                                  } else
                                                                          if (debug) $.writeln("renamed "+myLink.filePath+" to "+myNewLinkName+" see?:"+myOldImageHDfile.name);
                                                myLink.insertLabel("relinked", "yes");
                                                myLink.relink( myOldImageHDfile );
                                                try {
                                                    myLink = myLink.update();
                                                }
                                                catch(err) {}
                                            
                                                for (f = myMultiUsedLink.length-1; f >= 0 ; f--)
                                                {
                                                    var myCurrLink = myMultiUsedLink[f];
                                                      if (debug) $.writeln("f["+f+"] extracted label is "+myCurrLink.extractLabel("relinked"));
                                                      if (myCurrLink.extractLabel("relinked") != "yes") {
                                                       myCurrLink.relink( myOldImageHDfile );
                                                        myCurrLink.insertLabel("relinked", "yes");
                                                     }
                                                    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[f].extractLabel("relinked") != "") {
                                                        myDoc.links[f].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;
                                            }
                                            

                                             

                                            p.s.: why do some of you like to name variables "myVariable"? What's wrong with "variable"?

                                            • 20. Re: Renaming Artwork Automatically
                                              Kasyan Servetsky Level 5

                                              Hi John,

                                               

                                              I talked to Amy on private by e-mail and she sent me a sample file. I remade the script and it seems to be working (ID 6.0.4, Mac), but I hadn't enough time to totally test it yet since I was terribly busy that day. I had saved an inx copy of the file and run it on my home computer today (ID 6.0.4, Windows), but the result was different — a warning appeared: "The file such and such has different layouts than the imported version, the link will be updated with the source files current layer visibility settings" and some images changed their scaling. I haven't sorted out why this happens yet.

                                              I'm posting the latest version of the script. I added a logging feature to it — it creates a text file on the desktop. And it shows a multiply-linked image while prompting the user to enter a new name for it.

                                               

                                              p.s.: why do some of you like to name variables "myVariable"? What's wrong with "variable"?

                                              I do this mostly from force of habit: when I was learning scripting I studied Ole's sample files — he always names variables starting with "my". I think this makes sense: this way an inexperienced scripter avoids unintentionally using some reserved JS word. I also name my functions starting with upper case letter, as recommended by Kris Coppieters, so that not to mess up JS built in functions.

                                               

                                              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[k].itemLink.name;
                                                   }
                                              
                                                   crearLabels();
                                              
                                                   var myPages = myDoc.pages;
                                                   // Pages
                                                   for ( p = 0; p < myPages.length; p++ )
                                                   {
                                                        var myPageNumber = pad000(myPages[p].name);
                                              
                                                        var myLinks = myPages[p].allGraphics;
                                                        var myASCII = 97;
                                                        for ( k = myLinks.length - 1; k >= 0; k-- )
                                                        {
                                                             var myLink = myLinks[k].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[m];
                                                        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[n].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[a]);
                                                        }
                                                   }
                                              
                                                   WriteToFile("\r--------------------- Script finished -- " + GetDate() + " ---------------------\r\r");
                                                   
                                                   if (myLinksCounter == 0) {
                                                        alert("No links have been renamed", "Rename Links Script");
                                                   }
                                                   if (myLinksCounter == 1) {
                                                        alert("One link has been renamed", "Rename Links Script");
                                                   }
                                                   else if (myLinksCounter > 1) {
                                                        alert(myLinksCounter  + " links have been renamed", "Rename Links Script");
                                                   }
                                              
                                              }
                                              //--------------------------------------------- Functions ------------------------------------------------
                                              // Check how many times the link was placed
                                              function LinkUsage(myLink) {
                                                   var myLinksNumber = 0;
                                                        for (var c =  0; c < myDoc.links.length; c++) {
                                                        if (myLink.filePath == myDoc.links[c].filePath) {
                                                             myLinksNumber += 1;
                                                        }
                                                   }
                                                   return myLinksNumber;
                                              }
                                              //--------------------------------------------------------------------------------------------------------------
                                              // Relink the links placed more than once
                                              function processMultiUsedLinks(myLink) {
                                                   var myExtension = myLink.name.substr(myLink.name.lastIndexOf( "." ));
                                                   var myMultiUsedLink = new Array();
                                                   var myAllLinks = myDoc.links;
                                                   
                                                   for (var d = 0; d < myAllLinks.length; d++)  {
                                                        if (myAllLinks[d].filePath == myLink.filePath) {
                                                             myMultiUsedLink.push(myAllLinks[d]);
                                                        }
                                                   }
                                                   try {
                                                        myLink.show();
                                                   }
                                                   catch(err) {}
                                                   
                                                   var myNewLinkName = prompt ("Enter a name for this image", GetFileNameOnly(myLink.name), "This image is placed " + myMultiUsedLink .length + " times");
                                                   if (myNewLinkName) {
                                                        if ( myNewLinkName + myExtension != myLink.name ) {
                                                             var myOldImageHDfile = new File( myLink.filePath );
                                                             var myRenameResult = myOldImageHDfile.rename( myNewLinkName + myExtension );
                                                             if (myRenameResult) {
                                                                  myLink.insertLabel("relinked", "yes");
                                                                  myLink.relink( myOldImageHDfile );
                                                                  try {
                                                                       myLink = myLink.update();
                                                                  }
                                                                  catch(err) {}
                                                                  
                                                                  WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");
                                                                  myLinksCounter++;
                                              
                                                                  for (f = myMultiUsedLink.length-1; f >= 0 ; f--)
                                                                  {
                                                                       var myCurrLink = myMultiUsedLink[f];
                                                                       if ( myNewLinkName + myExtension != myCurrLink.name ) {
                                                                            myCurrLink.insertLabel("relinked", "yes");
                                                                            myCurrLink.relink( myOldImageHDfile );
                                              
                                                                            try {
                                                                                 myCurrLink = myLink.update();
                                                                            }
                                                                            catch(err) {}
                                                                       }
                                                                  }
                                                             }
                                                             else     {
                                                                  if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {
                                                                       WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + myExtension + " because the file already exists\n");
                                                                  }
                                                                  else {
                                                                       WriteToFile("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");
                                                                  }
                                                             }
                                                        }
                                                   }
                                                   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[f].extractLabel("relinked") != "") {
                                                             myDoc.links[f].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;
                                              }
                                              //--------------------------------------------------------------------------------------------------------------
                                              function GetFileNameOnly(myFileName) {
                                                   var myString = "";
                                                   var myResult = myFileName.lastIndexOf(".");
                                                   if (myResult == -1) {
                                                        myString = myFileName;
                                                   }
                                                   else {
                                                        myString = myFileName.substr(0, myResult);
                                                   }
                                                   return myString;
                                              }
                                              //--------------------------------------------------------------------------------------------------------------
                                              function IsObjInArray(myObj, myArray) {
                                                   for (x in myArray) {
                                                        if (myObj.filePath == myArray[x].filePath) {
                                                             return true;
                                                        }
                                                   }
                                                   return false;
                                              }
                                              //--------------------------------------------------------------------------------------------------------------
                                              function WriteToFile(myText) {
                                                   myFile = new File("~/Desktop/Rename Links Script.txt");
                                                   if ( myFile.exists ) {
                                                        myFile.open("e");
                                                        myFile.seek(0, 2);
                                                   }
                                                   else {
                                                        myFile.open("w");
                                                   }
                                                   myFile.write(myText); 
                                                   myFile.close();
                                              }
                                              //--------------------------------------------------------------------------------------------------------------
                                              function GetDate() {
                                                   var myDate = new Date();
                                                   if ((myDate.getYear() - 100) < 10) {
                                                        var myYear = "0" + new String((myDate.getYear() - 100));
                                                   } else {
                                                        var myYear = new String ((myDate.getYear() - 100));
                                                   }
                                                   var myDateString = (myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myYear + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();
                                                   return myDateString;
                                               }
                                              //--------------------------------------------------------------------------------------------------------------
                                              
                                              • 21. Re: Renaming Artwork Automatically
                                                amy_emcdesign Level 1

                                                wow this looks complex, thanks so much for your help everyone

                                                 

                                                 

                                                sorry for the multiple threads, I was concerned that the old threads I'd posted in were flagged as 'answered' so I made my own, but I didn't mean to swamp the forum, apologies.

                                                • 22. Re: Renaming Artwork Automatically
                                                  goldaochacademy

                                                  I realize this is very late to the party.  I've installed this script (the one in message 20 in this thread) and it does just what it is supposed to.

                                                  But - How do I edit it to stop it from renaming images on the master page?  I'm not a scripter, just hunting for something that does what I need it to!

                                                  • 23. Re: Renaming Artwork Automatically
                                                    winterm Level 4

                                                    It seems like we have some mistype in line 212?

                                                    Otherwise, great script, Kasyan!

                                                     

                                                    Слава Україні!

                                                     

                                                    • 24. Re: Renaming Artwork Automatically
                                                      Kasyan Servetsky Level 5

                                                      @winterm Thank you for supporting my country in times of trouble.

                                                       

                                                      @goldaochacademy We can simply remove the part of the code which loops through master pages: lines 69–118

                                                      However, there’s a possibility that an image is placed 2+ times both on a page and on a master page.

                                                      • 25. Re: Re: Renaming Artwork Automatically
                                                        Kasyan Servetsky Level 5

                                                        I made many versions of the script. Below is the latest variant in case someone is interested.

                                                         

                                                        Rename links. Version 1.3

                                                        const gScriptName = "Rename links";
                                                        const gScriptVersion = "1.3";
                                                        var o = {};
                                                        CreateDialog();
                                                        //===================================== FUNCTIONS  ======================================
                                                        function CreateDialog() {
                                                            var w = new Window("dialog", gScriptName + " - " + gScriptVersion);
                                                            w.alignChildren = "fill";
                                                            
                                                            // ISBN    
                                                            w.p = w.add("panel", undefined, "");
                                                            w.p.orientation = "column";
                                                            w.p.alignChildren = "left";
                                                        
                                                            w.p.g = w.p.add("group");
                                                            w.p.g.orientation = "row";
                                                            w.p.g.st = w.p.g.add("statictext", undefined, "ISBN:");
                                                            w.p.g.et = w.p.g.add("edittext");
                                                            w.p.g.et.characters = 13;
                                                            if (app.documents.length == 0) {
                                                                w.p.g.et.text = "1234567890123";
                                                            }
                                                            else {
                                                                try {
                                                                    w.p.g.et.text = app.activeDocument.name.match(/^\d{13,}/)[0];
                                                                }
                                                                catch(err) {
                                                                    w.p.g.et.text = "1234567890123";
                                                                }
                                                            }
                                                            w.p.g.et.onChange = function() {
                                                                if (w.p.g.et.text.match(/\d{13,}/) == null) alert("\"" + w.p.g.et.text + "\" is not correct ISBN number. It should consist of 13 digits."); 
                                                            }    
                                                            
                                                            w.p.cb = w.p.add("checkbox", undefined, "Create log file on the desktop");
                                                            w.p.cb.value = true;
                                                            
                                                            w.p1 = w.add("panel", undefined, "Process:"); // Settings
                                                            w.p1.orientation = "column";
                                                            w.p1.alignChildren = "left";
                                                            w.p1.rb = w.p1.add("radiobutton", undefined, "Active document");
                                                            w.p1.rb1 = w.p1.add("radiobutton", undefined, "All documents in the selected folder");
                                                            if (app.documents.length == 0) {
                                                                w.p1.rb1.value = true;
                                                                w.p1.rb.enabled = false;
                                                            }
                                                            else {
                                                                w.p1.rb.value = true;
                                                            }
                                                            
                                                            // Buttons
                                                            w.g2 = w.add("group");
                                                            w.g2.orientation = "row";   
                                                            w.g2.alignment = "center";
                                                            w.g2.ok = w.g2.add("button", undefined, "OK", {name:"ok" });
                                                            w.g2.cancel = w.g2.add("button", undefined, "Cancel", {name:"cancel"});
                                                            
                                                            var showDialog = w.show();
                                                            
                                                            if (showDialog == 1) {
                                                                if (w.p1.rb.value) {
                                                                    o.scope = 1; // Active document
                                                                }
                                                                else {
                                                                    o.scope = 2; // All documents in the selected folder
                                                                }
                                                            
                                                                o.isbn = w.p.g.et.text;
                                                                o.log = (w.p.cb.value) ? true : false;
                                                                
                                                                Main();
                                                            }
                                                            
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function Main() {
                                                            if (o.scope == 1) { // Active document
                                                                ProcessActiveDoc();
                                                            }
                                                            else if (o.scope == 2) { // All documents in the selected folder
                                                                BatchProcessDocs();
                                                            }
                                                        
                                                            alert("Finished.", gScriptName);
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function ProcessActiveDoc() {
                                                            var firstPageName, lastPageName, newFile;
                                                            var doc = app.activeDocument;
                                                            // Main 
                                                            o.mainFolderPath = doc.filePath.parent.fullName + "/" + o.isbn + "/";
                                                            o.mainFolder = new Folder(o.mainFolderPath);
                                                            if (!o.mainFolder.exists) o.mainFolder.create();
                                                            // Images
                                                            o.imagesFolderPath = o.mainFolderPath + o.isbn + "_images/";
                                                            o.imagesFolder = new Folder(o.imagesFolderPath);
                                                            if (!o.imagesFolder.exists) o.imagesFolder.create();
                                                            
                                                            if (doc.name.match(/^\d{13,}/) == null) {
                                                                firstPageName = doc.pages[0].name;
                                                                lastPageName = doc.pages[doc.pages.length-1].name;
                                                                newFile = new File(o.mainFolderPath + o.isbn + "_int_" + ZeroPad(firstPageName, 3) + "-" + ZeroPad(lastPageName, 3) + ".indd");
                                                                if (newFile.exists) ErrorExit("File \"" + newFile.fsName + "\" already exists."); // Don't overwrite any docs
                                                                doc = doc.save(newFile);
                                                                ProcessDoc(doc);
                                                            }
                                                            else {
                                                                ProcessDoc(doc);
                                                            }
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function BatchProcessDocs() {
                                                            var file, doc, firstPageName, lastPageName, newFile;
                                                            var folder = Folder.selectDialog("Select a folder with InDesign documents.");
                                                            if (folder == null) exit();
                                                            var files = GetFiles(folder);
                                                            if (files.length == 0) ErrorExit("No InDesign documents were found in the selected folder.");
                                                            // Create "main" and "images" folders
                                                            o.mainFolderPath = folder.fullName + "/" + o.isbn + "/";
                                                            o.mainFolder = new Folder(o.mainFolderPath);
                                                            if (!o.mainFolder.exists) o.mainFolder.create();
                                                            o.imagesFolderPath = o.mainFolderPath + o.isbn + "_images/";
                                                            o.imagesFolder = new Folder(o.imagesFolderPath);
                                                            if (!o.imagesFolder.exists) o.imagesFolder.create();
                                                            
                                                            for (var i = 0; i < files.length; i++) {
                                                                file = files[i];
                                                                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
                                                                doc = app.open(file);
                                                                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
                                                                firstPageName = doc.pages[0].name;
                                                                lastPageName = doc.pages[doc.pages.length-1].name;
                                                                newFile = new File(o.mainFolderPath + o.isbn + "_int_" + ZeroPad(firstPageName, 3) + "-" + ZeroPad(lastPageName, 3) + ".indd");
                                                                if (newFile.exists) ErrorExit("File \"" + newFile.fsName + "\" already exists."); // Don't overwrite any docs
                                                                if (doc.name.match(/^\d{13,}/) == null) doc = doc.save(newFile);
                                                                ProcessDoc(doc);
                                                                doc.save(doc.fullName);
                                                                doc.close(SaveOptions.YES);
                                                            }
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function ProcessDoc(doc) {
                                                            var link, image, ext, threeDigits, newLinkFile, actualPpi, effectivePpi, space, pageName;
                                                            if (o.log) WriteToFile("===========================================================================\r" + GetDate() + "\r---------------------------------------------------------------------------\rFile name: " + doc.name + "\r");
                                                            var usedNumbers = GetUsedNumbers(o.imagesFolder);
                                                            var counter = 1;
                                                            
                                                            var links = doc.links;
                                                            var linksCounter = 0;
                                                            
                                                            for (var i = links.length-1; i >= 0; i--) {
                                                                link = links[i];
                                                                if (link.name.substr(0,13) == o.isbn) continue;
                                                                image = link.parent;
                                                                ext = GetExtension(link.name);
                                                                
                                                                while (GetArrayIndex(usedNumbers, counter) != -1) {
                                                                    counter++;
                                                                }
                                                                
                                                                usedNumbers.push(counter);
                                                                threeDigits = ZeroPad(counter, 3);
                                                                
                                                                newLinkFile = new File(o.imagesFolderPath + o.isbn + "_a" + threeDigits + "." + ext);
                                                                
                                                                if (o.log) {
                                                                    try {
                                                                        actualPpi = image.actualPpi[0] + "x" + image.actualPpi[1];
                                                                        effectivePpi = image.effectivePpi[0] + "x" + image.effectivePpi[1];
                                                                    }
                                                                    catch(err) {
                                                                        actualPpi = "N/A";
                                                                        effectivePpi = "N/A";
                                                                    }
                                                                
                                                                    try {
                                                                        space = image.space;
                                                                    }
                                                                    catch(err) {
                                                                        space = "N/A";
                                                                    }
                                                                
                                                                    try {
                                                                        pageName = link.parent.parentPage.name;
                                                                    }
                                                                    catch(err) {
                                                                        pageName = "N/A";
                                                                    }
                                                                    
                                                                    linksCounter++;
                                                                    WriteToFile(linksCounter + " - " + link.name + " ==> " + newLinkFile.name + "\r\tActual ppi: " + actualPpi + "\r\tEffective ppi: " + effectivePpi + "\r\tColor space: " + space+ "\r\tPage: " + pageName);
                                                                }
                                                                
                                                                try {
                                                                    link.copyLink(newLinkFile);
                                                                }
                                                                catch(err) {
                                                                    $.writeln(err.message + ", line: " + err.line);
                                                                }
                                                            }
                                                        
                                                            if (o.log && linksCounter == 0) WriteToFile("No links were renamed.");
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function GetUsedNumbers(theFolder) {
                                                            var file, baseName, match;
                                                            var numList = [];
                                                            var fileList = theFolder.getFiles();
                                                            
                                                            for (var i = 0; i < fileList.length; i++) {
                                                                file = fileList[i];
                                                                baseName = GetFileName(file.name);
                                                                match = baseName.match(/\d{3,}$/);
                                                                if (match != null) numList.push(Number(match[0]));
                                                            }
                                                            
                                                            return numList;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function ZeroPad(num, digit) {
                                                            var tmp = num.toString();
                                                            while (tmp.length < digit) {
                                                                tmp = "0" + tmp;
                                                            }
                                                            return tmp;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function GetArrayIndex(arr, val) {
                                                            for (var i = 0; i < arr.length; i++) {
                                                                if (arr[i] == val) {
                                                                    return i;
                                                                }
                                                            }
                                                            return -1;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function GetFileName(fileName) {
                                                            var str = "";
                                                            var res = fileName.lastIndexOf(".");
                                                            if (res == -1) {
                                                                str = fileName;
                                                            }
                                                            else {
                                                                str = fileName.substr(0, res);
                                                            }
                                                            return str;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function GetExtension(name) {
                                                            var idx = name.lastIndexOf( "." );
                                                            var ext = "";
                                                            if (idx > -1) {
                                                                ext = name.substr((idx + 1));
                                                            }
                                                            return ext;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function WriteToFile(text) {
                                                            var file = new File("~/Desktop/" + gScriptName + ".txt");
                                                            if (file.exists) {
                                                                file.open("e");
                                                                file.seek(0, 2);
                                                            }
                                                            else {
                                                                file.open("w");
                                                            }
                                                            file.write(text + "\r"); 
                                                            file.close();
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function ErrorExit(error, icon) {
                                                            alert(error, gScriptName + " - " + gScriptVersion, icon);
                                                            exit();
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function GetDate() {
                                                            var date = new Date();
                                                            if ((date.getYear() - 100) < 10) {
                                                                var year = "0" + new String((date.getYear() - 100));
                                                            }
                                                            else {
                                                                var year = new String((date.getYear() - 100));
                                                            }
                                                            var dateString = (date.getMonth() + 1) + "/" + date.getDate() + "/" + year + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                                                            return dateString;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        function GetFiles(theFolder) {
                                                            var files = [],
                                                            fileList = theFolder.getFiles(),
                                                            i, file;
                                                            
                                                            for (i = 0; i < fileList.length; i++) {
                                                                file = fileList[i];
                                                                if (file instanceof Folder) {
                                                                    files = files.concat(GetFiles(file));
                                                                }
                                                                else if (file instanceof File && file.name.match(/\.indd$/i)) {
                                                                    files.push(file);
                                                                }
                                                            }
                                                        
                                                            return files;
                                                        }
                                                        //--------------------------------------------------------------------------------------------------------------------------------------------------------
                                                        

                                                         

                                                        After line #152 you can add the following line to skip images on master pages:

                                                        if (link.parent.parent.parent.constructor.name == "MasterSpread") continue;

                                                        It will work only if the images are placed directly on master pages (not nested, in tables, anchored, etc.)

                                                        • 26. Re: Renaming Artwork Automatically
                                                          kajzica Level 1

                                                          here is working script which can deal with MULTIPLE instances same link, also skip files on master pages...

                                                           

                                                          var myDoc = app.activeDocument;

                                                          var myAllLinks = myDoc.allGraphics;

                                                          var myMultipleLinks = new Array();

                                                          var myMultipleLinksName = new Array();

                                                          var myLinksCounter = 1;

                                                          var myPrepend = prompt("Example: thebook_08765", "Job description", "Please enter job description");

                                                          if (!myPrepend) exit();

                                                          myPrepend += "_str_";

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

                                                               {

                                                                   if(myAllLinks[k].itemLink == null){

                                                                       myAllLinks.splice(k,1);

                                                                       k--;

                                                                       continue;

                                                                    }

                                                                    var myLinkName = myAllLinks[k].itemLink.name;

                                                               }

                                                           

                                                               crearLabels();

                                                           

                                                               var myPages = myDoc.pages;

                                                               // Pages

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

                                                               {

                                                                    var myPageNumber = pad000(myPages[p].name);

                                                           

                                                                    var myLinks = myPages[p].allGraphics;

                                                                    var myASCII = 97;

                                                                    for ( k = myLinks.length - 1; k >= 0; k-- )

                                                                    {

                                                                         var myLink = myLinks[k].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 myNewLinkName2 = myPrepend + myPageNumber + String.fromCharCode( myASCII ) + myExtension;

                                                                                        myMultipleLinksName.push(myNewLinkName2);

                                                                                        myASCII++;

                                                                                   }

                                                                              }

                                                                         }

                                                                    }

                                                               }

                                                           

                                                               var myMasterSpreads = myDoc.masterSpreads;

                                                               // Master spreads

                                                               for ( m = 0; m < myMasterSpreads.length; m++ )

                                                               {

                                                                    var myMastSpr = myMasterSpreads[m];

                                                                    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[n].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);

                                                                                        var myLinkLetter2 = (myLinks.length == 1) ? "" : String.fromCharCode( myASCII );

                                                                                        var myNewLinkName2 = myPrepend + '_master_' + myPrefix + myLinkLetter2 + myExtension;

                                                                                        myMultipleLinksName.push(myNewLinkName2);

                                                                                        myASCII++;

                                                                                  }

                                                                              }

                                                                         }

                                                                    }

                                                               }

                                                               // Multiple images

                                                               if (myMultipleLinks.length > 0) {

                                                                    for ( a = myMultipleLinks.length - 1; a >= 0; a-- )

                                                                    {

                                                                         processMultiUsedLinks(myMultipleLinks[a], myMultipleLinksName[a]);

                                                                    }

                                                               }

                                                           

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

                                                              

                                                               if (myLinksCounter == 0) {

                                                                    alert("No links have been renamed", "Rename Links Script");

                                                               }

                                                               if (myLinksCounter == 1) {

                                                                    alert("One link has been renamed", "Rename Links Script");

                                                               }

                                                               else if (myLinksCounter > 1) {

                                                                    alert(myLinksCounter  + " links have been renamed", "Rename Links Script");

                                                               }

                                                           

                                                          }

                                                          //--------------------------------------------- Functions ------------------------------------------------

                                                          // Check how many times the link was placed

                                                          function LinkUsage(myLink) {

                                                               var myLinksNumber = 0;

                                                                    for (var c =  0; c < myDoc.links.length; c++) {

                                                                    if (myLink.filePath == myDoc.links[c].filePath) {

                                                                         myLinksNumber += 1;

                                                                    }

                                                               }

                                                               return myLinksNumber;

                                                          }

                                                          //---------------------------------------------------------------------------------------- ----------------------

                                                          // Relink the links placed more than once

                                                          function processMultiUsedLinks(myLink, naziv) {

                                                               var myExtension = "";

                                                               var myMultiUsedLink = new Array();

                                                               var myAllLinks = myDoc.links;

                                                               for (var d = 0; d < myAllLinks.length; d++)  {

                                                                    if (myAllLinks[d].filePath == myLink.filePath) {

                                                                         myMultiUsedLink.push(myAllLinks[d]);

                                                                    }

                                                               }

                                                               try {

                                                                    myLink.show();

                                                               }

                                                               catch(err) {}

                                                              

                                                               var myNewLinkName = naziv; //prompt ("Enter a name for this image", GetFileNameOnly(myLink.name), "This image is placed " + myMultiUsedLink .length + " times");

                                                               if (myNewLinkName) {

                                                                    if ( myNewLinkName + myExtension != myLink.name ) {

                                                                         var myOldImageHDfile = new File( myLink.filePath );

                                                                         var myRenameResult = myOldImageHDfile.rename( myNewLinkName + myExtension );

                                                                         if (myRenameResult) {

                                                                              myLink.insertLabel("relinked", "yes");

                                                                              myLink.relink( myOldImageHDfile );

                                                                              try {

                                                                                   myLink = myLink.update();

                                                                              }

                                                                              catch(err) {}

                                                                             

                                                                              WriteToFile(((myLinksCounter < 10) ? (" " + myLinksCounter) : myLinksCounter) + " - " + myOldImageHDfile.name + " --> " + myNewLinkName + "\n");

                                                                              myLinksCounter++;

                                                           

                                                                              for (f = myMultiUsedLink.length-1; f >= 0 ; f--)

                                                                              {

                                                                                   var myCurrLink = myMultiUsedLink[f];

                                                                                   if ( myNewLinkName + myExtension != myCurrLink.name ) {

                                                                                        myCurrLink.insertLabel("relinked", "yes");

                                                                                        myCurrLink.relink( myOldImageHDfile );

                                                           

                                                                                        try {

                                                                                             myCurrLink = myLink.update();

                                                                                        }

                                                                                        catch(err) {}

                                                                                   }

                                                                              }

                                                                         }

                                                                         else     {

                                                                              if (new File(myOldImageHDfile.parent + "/" + myNewLinkName + myExtension).exists) {

                                                                                   $.writeln("CAN'T RENAME LINK -- " + myOldImageHDfile.name + " to " + myNewLinkName + myExtension + " because the file already exists\n");

                                                                              }

                                                                              else {

                                                                                   $.writeln("CAN'T RENAME LINK -- " + myOldImageHDfile.name + "\n");

                                                                              }

                                                                         }

                                                                    }

                                                               }

                                                               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[f].extractLabel("relinked") != "") {

                                                                         myDoc.links[f].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;

                                                          }

                                                          //---------------------------------------------------------------------------------------- ----------------------

                                                          function GetFileNameOnly(myFileName) {

                                                               var myString = "";

                                                               var myResult = myFileName.lastIndexOf(".");

                                                               if (myResult == -1) {

                                                                    myString = myFileName;

                                                               }

                                                               else {

                                                                    myString = myFileName.substr(0, myResult);

                                                               }

                                                               return myString;

                                                          }

                                                          //---------------------------------------------------------------------------------------- ----------------------

                                                          function IsObjInArray(myObj, myArray) {

                                                               for (x in myArray) {

                                                                    if (myObj.filePath == myArray[x].filePath) {

                                                                         return true;

                                                                    }

                                                               }

                                                               return false;

                                                          }

                                                          //---------------------------------------------------------------------------------------- ----------------------

                                                          function WriteToFile(myText) {

                                                               myFile = new File("~/Desktop/Rename Links Script.txt");

                                                               if ( myFile.exists ) {

                                                                    myFile.open("e");

                                                                    myFile.seek(0, 2);

                                                               }

                                                               else {

                                                                    myFile.open("w");

                                                               }

                                                               myFile.write(myText);

                                                               myFile.close();

                                                          }

                                                          //---------------------------------------------------------------------------------------- ----------------------

                                                          function GetDate() {

                                                               var myDate = new Date();

                                                               if ((myDate.getYear() - 100) < 10) {

                                                                    var myYear = "0" + new String((myDate.getYear() - 100));

                                                               } else {

                                                                    var myYear = new String ((myDate.getYear() - 100));

                                                               }

                                                               var myDateString = (myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myYear + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();

                                                               return myDateString;

                                                          }

                                                          //---------------------------------------------------------------------------------------- ----------------------

                                                          • 27. Re: Renaming Artwork Automatically
                                                            chillbot75

                                                            Hi .

                                                             

                                                            This is a great script. I've been trying to find something as powerful as this. I'm not a scriptor.

                                                            There are a couple specifics that I"m looking for my needs.

                                                             

                                                            I was curious if you might know how to modify this so that it would do certain file types?

                                                            I am trying to name all .tif files in sequence. And, all .psd files in sequence, etc.

                                                            I also don't need the naming to correspond to page number. In essence what I'm looking for naming is something like the following:

                                                             

                                                            image001.jpg

                                                            image002.jpg

                                                            image003.jpg

                                                            image001.tif

                                                            image002.tif

                                                            image003.tif

                                                            image001.psd

                                                            image002.psd

                                                            image003.psd

                                                             

                                                            Thanks in advance. Please let me know if this is at all possible.

                                                            Also, let me know if there's anything else you might need from me.

                                                             

                                                            Thanks and cheers!