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

GREP Script for Illustrator

Explorer ,
Apr 27, 2023 Apr 27, 2023

I've been a huge fan of GREPs with InDesign, and wanted a similar result in Illustrator to automate some Slug info replacements. So here's my script for anyone looking/needing it.

 

var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();
var year = d.getFullYear().toString().substr(-2);
var dateString = month + '.' + day + '.' + year;

// Replace placeholders in all text frames
var doc = app.activeDocument;
for (var i = 0; i < doc.textFrames.length; i++) {
    var textLayer = doc.textFrames[i];
    if (/\{MDY\}|\{F\}|\{C\}/.test(textLayer.contents)) {
        textLayer.contents = textLayer.contents.replace(/\{MDY\}/g, dateString);
        var docName = doc.name.replace(/\.[^\.]+$/, ''); // remove the file extension
        textLayer.contents = textLayer.contents.replace(/\{F\}/g, docName);
        textLayer.contents = textLayer.contents.replace(/\{C\}/g, "YOURNAME");
    }
}

 

This will replace the following wildcards:

{MDY} = month.day.year

{F} = filename without the extension

{C} = your name or initials

 

Obviously, im not as experienced as some on here, but i get a little better everyday. So hopefully it helps someone out there if you're like me and hate typing job numbers, file names, dates, etc. Modify to taste and keep on cooking. 😉

TOPICS
Scripting
869
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
Adobe
Community Expert ,
Apr 27, 2023 Apr 27, 2023

Hi @sublimechaos, thanks for sharing! - Mark

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
Mentor ,
Apr 28, 2023 Apr 28, 2023
LATEST

Neat, thanks.

(No upvote on original posts)

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