Skip to main content
New Participant
April 28, 2018
Answered

Find and replace text across multiple Illustrator files

  • April 28, 2018
  • 4 replies
  • 17037 views

With the printers now looking for AI or EPS files, I have run into this problem a lot.

Is there a way to find and replace text across multiple Illustrator files like you can do in Indesign & Dreamweaver? It would save me days of double-clicking and pasting.

Please help.

Wayne

    Correct answer CarlosCanto

    Below is a link to an example folder. I have to replace the XXXX with New York City in all 8 EPS files.

    Then repeat that for about 400 locations.

    WeTransfer


    Hi Wayne, here's a script that replaces XXXX with NEW YORK across all open documents. Let me know if you need help changing the script to find something more meaningful.

     

     

    // findReplace.jsx
    // carlos canto
    // https://forums.adobe.com/thread/2484457
    
    function main () {
        var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter=0;
        for (var a=0; a<app.documents.length; a++) {
            idoc = app.documents[a];
    
            search_string = /xxxx/gi; // g for global search, remove i to make a case sensitive search
            replace_string = "NEW YORK";
             
            tframes = idoc.textFrames;
             
            for (i = 0 ; i < tframes.length; i++) {
                tframe = tframes[i];
                new_string = tframe.contents.replace(search_string, replace_string);
    
                if (new_string != tframe.contents) {
                    tframe.contents = new_string;
                    counter++;
                }
            }
        }
        alert(counter + ' changes were made');
    }
    
    main();

     

     

     

    4 replies

    New Participant
    April 9, 2025

    Hi @CarlosCanto, thank you very much! The script seems to be working just fine. The only thing it messes up is formatting. Once there's some text in bold or with a different color at the beginning of the text area, the script changes the string but the whole text area also inherits the formatting from the very first character in the text area. Could you please provide some clarification on how to deal with this? Thank you so much!

    CarlosCanto
    Braniac
    April 5, 2020

    here you go, I added a prompt to enter search/replace strings. You're correct, if you have a lot of text, Illustrator will freeze but it's still working on the background. Just wait for the scrip to finish. I'll add a progress bar when I have more free time.

     

    // findReplace v4.jsx
    // carlos canto
    // https://forums.adobe.com/thread/2484457
    
    function main () {
        var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter=0;
        
        search_string = Window.prompt ('Enter Search string', 'search string', 'Find/Replace Across All Open Documents');
        
        if (search_string == null) {
            alert ('Cancelled by user');
            return;
        }
    
        replace_string = Window.prompt ('Enter Replace string', 'replace string', 'Find/Replace Across All Open Documents');
        
        if (replace_string == null) {
            alert ('Cancelled by user');
            return;
        }
    
        for (var a=0; a<app.documents.length; a++) {
            idoc = app.documents[a];
             
            tframes = idoc.textFrames;
             
            for (i = 0 ; i < tframes.length; i++) {
                tframe = tframes[i];
                new_string = tframe.contents.replace(new RegExp(search_string, 'g'), replace_string);
                
                if (new_string != tframe.contents) {
                    tframe.contents = new_string;
                    counter++;
                }
            }
        }
        alert(counter + ' changes were made');
    }
    
    main();
    
    

     

    blockstation
    Known Participant
    April 5, 2020

    Thank you very much Carlos!

    This is fantatstic.

    Do you know, which GREP commands work with Illustrator?

    I just tried the full stop which works like expected, also with the plus modifier.

    For troubleshooting i tried to wrap your script into an undo functionality like it has been described here:
    https://indesignsecrets.com/add-undo-to-your-script.php
    but this only seems to work with InDesign scripts.

    Thank you very much & stay healthy!

    blockstation
    Known Participant
    April 4, 2020

    Hi Carlos!
    The Scipt could be really useful for me.

    Might it be possible to have something like a search & replace dialog instead of the necesitty to change the code?

    This would be fantastic!

    While doing a search & replace on documents with a large amount of text boxes it seems like illustrator crashes but mostly it doesn't - it's only not responding. I guess thats because the script needs to go through all text boxes in all open documents.

    So something like a progress bar would also be very useful.

    Kurt Gold
    Braniac
    April 29, 2018

    In older versions of Illustrator that used to work with Batch processing action(s), but I can remember that some users claimed that it doesn't work anymore or not as expected.

    Which version of Illustrator are you using? What are you trying to find and replace? Just one single word or various instances of single words? Or something else?

    New Participant
    May 3, 2018

    I am running CC2018.

    Here is the Scenario. I have 12 eps files with the client logo and the location (live type) underneath. The 12 files are just different brand standard colors.

    There are 430 different locations (430X12). Instead of hitting paste 12X430 times, I would like to do find and replace 430 times.

    New Participant
    May 17, 2019

    Carlos, this script has really changed my workflow! What would you suggest to do multiple search queries at once? I tried creating more variables and adding to the for loop, but it wasn't working properly...I'm not sure if I'm getting syntax wrong or what.

    I've tried just creating additional search and replace variables as well as an additional new_string variable. That just ran the second query, so I created new tframe and tframes variables and had the same result with the second one running...

    // findReplace.jsx

    // carlos canto

    // https://forums.adobe.com/thread/2484457

    function main () {

        var idoc, search_string, replace_string, search_string1, replace_string1, tframes, tframes1, i, tframe, tframe1, new_string, new_string1=0;

        for (var a=0; a<app.documents.length; a++) {

            idoc = app.documents;

            search_string = /\d+\/\d+\/(18|19)/gi; // g for global search, remove i to make a case sensitive search

            replace_string = "01/30/19";

            search_string1 = /(REV) \dv\d+/gi; // g for global search, remove i to make a case sensitive search

            replace_string1 = "$1 4v0";

            tframes = idoc.textFrames;

            tframes1 = idoc.textFrames;

            for (i = 0 ; i < tframes.length; i++) {

                tframe = tframes;

                tframe1 = tframes;

                new_string = tframe.contents.replace(search_string, replace_string);

                new_string1 = tframe1.contents.replace(search_string1, replace_string1);

                if (new_string != tframe.contents) {

                tframe.contents = new_string;

                }

                if (new_string1 != tframe1.contents) {

                tframe1.contents = new_string1;

                }

            }

        }

    }

    main();


    Hello Wayne and all pal,  may I ask what is the exact step to copy the above script/code, and successfully run it to multiple opened AI file? Why it seemed all knows the step how to copy/save this code to what format, and open/import it in or with what?     Assuming I have zero knowledge in script/code.

    Do I have to save it as Applescript of .jsx file?  which function/feature in Illustrator can import or run these code?

    MAY I ASK THE EXACT STEPS TO RUN THIS CODE:
    1). starting from copying it via web browser;
    2). change xxxxxx in script to the needed find text-string;
    3).  replace "NEW YORK" in script to the needed replace text-string;
    4). open ???? application, and paste these code into ????,  save in ????? format;
    5). open Adobe Illustrator cc, and the multiple AI files;
    6).  then....what?

    THANKS SO MUCH