PDA

View Full Version : Find / Replace Copyright notice in all AI files


Citromike
05-18-2007, 06:55 PM
Hi

In my quest to reduce the tedium around our office, I proposed to create an Apple script that would search for a text string which we place on a visible layer in all our Illlustrator files.

This should work on all the files in a folder, searching for

"Copyright 2000 BlahBlah Publishers, Inc."

and replace it with the same string with year 2007 or 2008.

I have found a couple ways of locating the string using the Actions pallette but it seems more laborious than simply opening the file and doing a quick edit by hand.

This seems a common task that many would have to perform, but in searching for a couple slow hours I find no examples.

I would welcome a generic design so my script could work on InDesign too, although I only have dozens of those files instead of 1000's of Illustrator files.

Can anyone point me in the right direction?

Thanks

Mike

nutella
05-21-2007, 01:51 PM
Well, Mike, it doesn't answer your question (unfortunately) but I don't do AppleScript. One reason is that it's not cross platform and second (major reason) is that i don't have the time to figure out what commands AppleScript has in general. These commands are NOT related to AI, but just in general text operations. Instead, I give you a javascript solution which is cross platform.

You can use the "ExtendScript Toolkit" that is also cross platform and comes with AI on both Windows and Mac. This is a script editor just like the AppleScript editor app.

Anyhow, this short script will search through all the textfields in a document and replace the year with another. You can specify the years in the script (didn't want to get too fancy). If you can translate the text operations into AppleScript then by all means...


var doc = app.activeDocument
if (doc.layers.length > 1) {
for (i = 0; i < doc.textFrames.length; i++) {
var theText = doc.textFrames[i].contents;
var offset = theText.indexOf("2006");
if (offset > -1) {
var str = theText.substr(0, offset) + "2007"
str += theText.substr(offset + 4, theText.length - (offset + 4));
doc.textFrames[i].contents = str;
}
}
}

(too bad the script looses indentation when I paste it in here...)

Cheers,

Citromike
05-21-2007, 02:27 PM
Hi Les,

Thanks very much for the tip about the JavaScript editor.

I modified your script a bit to find / replace "Copyright 2006" as these are math textbooks and chock full of numbers - don't want to change numbers that might appear in the other text streams.

We have to go through every single file as we convert to CS2; I have a script for that so I'll see if I can add this routine into the conversion process.

I appreciate the help.

Mike