Skip to main content
sublimechaos
Inspiring
April 27, 2023
Question

GREP Script for Illustrator

  • April 27, 2023
  • 2 replies
  • 1240 views

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. 😉

This topic has been closed for replies.

2 replies

Met1
Legend
April 28, 2023

Neat, thanks.

(No upvote on original posts)

m1b
Community Expert
Community Expert
April 27, 2023

Hi @sublimechaos, thanks for sharing! - Mark