Skip to main content
Participant
April 8, 2025
Question

A script to add the illustrator file name, minus extension, to a text field within the file.

  • April 8, 2025
  • 1 reply
  • 323 views

Hi, Im trying to find a way to add the illustrator file name to a text field within a table in the same illustrator file. When the file name gets updated, the text field also automatically gets updated. Similar to how it works in Indesign Text Variables > Insert Variable > File Name. Unfortuantely illustrator does not work in the same way.

 

I found a script to add the file name, but it doesnt update. If anyone has any scripts that would work, I would appreciate your feedback. Thanks!

1 reply

Sergey Osokin
Inspiring
April 9, 2025

So you close the file and rename it. You open the file again, and you want the text frame to update automatically? Scripts only change the document when you run the script.

 

If you have a text object with a key name in the file, you will need to run the script each time to insert the filename into it. Example:

(function (){
  var doc = app.activeDocument;
  var docName = doc.name.replace(/\.[^\.]+$/, '')
  var targetName = "filename";
  try {
    var target = doc.textFrames.getByName(targetName);
    target.contents = docName;
  } catch (error) {
    alert("Text frame '" + targetName + "' not found");
  }
})();

 

Participant
April 9, 2025

Thanks Sergey. Yes, I would ideally like it to work as it does in Indesign, as that is automatic. I guess there is no automated option for illustrator.