相关文章推荐
彷徨的仙人掌  ·  Windows ...·  7 月前    · 
帅呆的毛衣  ·  How to Import a ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to use javascript to update an Illustrator file. I have a script that will modify an open file in the desired way (really just a text find/replace, but the text is encoded in the Illustrator data). The problem is I have hundreds of these files that I want modified in the same way in a directory. Is there a way for me to do this without having to open every single one of these files?

I figure either: 1. there's a way to modify the existing javascript to read from the directory and load the files in the background, process them, save, and close. 2. I can write a Node.js script that can wrap the existing Illustrator javascript, but I'm not sure how to get it to recognize the "application" object and read the file the same way as when it's opened in Illustrator.

Thanks for any help!

Edit: Here's the functioning script (that only .

function FindAndReplaceScript_AllOpenDocuments(){      
        for(var i=app.documents.length -1; i > -1;  i--){      
        app.documents[i].activate();  
        var aDoc = app.documents[i];  
        var searchString = /OLDTEXT/gi;     
        var replaceString = 'NEWTEXT';       
        var theTF = aDoc.textFrames;      
        if (theTF.length > 0) {      
            for (var j = 0 ; j <theTF.length; j++) {      
                var aTF = theTF[j];      
                var newString = aTF.contents.replace(searchString, replaceString);      
                if (newString != aTF.contents) {      
                    theTF[j].contents = newString;      
FindAndReplaceScript_AllOpenDocuments();   
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.