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

Blank error box when trying to run a script in Illustrator

New Here ,
Aug 18, 2023 Aug 18, 2023

So i'm new to scripting but I'm trying to create a script that does a 'find and replace' for dates in Illustrator for my product label files. 

 

i used chat gpt to make the code and seems like it should work but i keep getting an error from Adobe that is just a yellow triangle with no words when i try to run it. 

 

Anybody seen this before? Or is my code wrong? I've tried using the mac script editor as well as text edit with the extension .jsx.

 

Nothing seems to work and any help would be awesome!

 

Thank you

 

Screenshot 2023-08-18 at 10.39.28 PM.pngexpand image

 

code i'm using below:

// Check if Adobe Illustrator is running

if (app.name === "Adobe Illustrator") {

  var doc = app.activeDocument;

  

  // Loop through all page items in the document

  for (var i = 0; i < doc.pageItems.length; i++) {

    var pageItem = doc.pageItems[i];

    

    // Check if the page item is a text frame

    if (pageItem instanceof TextFrame) {

      var textRange = pageItem.textRange;

      

      // Find and replace the text

      var newText = textRange.contents.replace(/3\/31/g, "8/24");

      

      // Update the text if replacement occurred

      if (newText !== textRange.contents) {

        textRange.contents = newText;

      }

    }

  }

  

  alert("Text replacement completed.");

} else {

  alert("Please run this script in Adobe Illustrator.");

}

TOPICS
General troubleshooting , How to , JavaScript
164
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2023 Aug 19, 2023
LATEST

Try the forum for Illustrator.

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