Hi,
Due to shifting of the code from old forum to the new forum, script gets corrupted. Here is teh updated version of the same script by Carlos.
// findReplace.jsx
// carlos canto
// https://forums.adobe.com/thread/2484457
function main() {
var idoc, search_string, replace_string, tframes, i, tframe, new_string, counter = 0;
for (var a = 0; a < app.documents.length; a++) {
idoc = app.documents;
search_string = /xxxx/gi; // g for global search, remove i to make a case sensitive search
replace_string = "NEW YORK";
tframes = idoc[a].textFrames;
for (i = 0; i < tframes.length; i++) {
tframe = tframes[i];
new_string = tframe.contents.replace(search_string, replace_string);
if (new_string != tframe.contents) {
tframe.contents = new_string;
counter++;
}
}
}
alert(counter + ' changes were made');
donate(File($.fileName).displayName);
}
main();
function donate(thisScript) {
var donateStrPref = 'aiscripts.com/donate/' + thisScript;
var donated = app.preferences.getStringPreference(donateStrPref);
if (donated != 'true') {
var showAgain = showDonateWindow();
if (showAgain) {
//alert('checked');
app.preferences.setStringPreference(donateStrPref, 'true');
}
}
}
function showDonateWindow() {
var win = new Window('dialog', 'https://www.paypal.me/aiscripts');
var lblDonate = win.add('staticText', undefined, 'Do you find the script valuable?\nDo you use the script commercially?\nPlease consider donating', { multiline: true });
var grp = win.add('group');
var btnCancel = grp.add('button', undefined, 'Cancel');
var btnDonate = grp.add('button', undefined, 'Donate');
var chk = win.add('checkbox', undefined, "Do not show me this message again");
btnDonate.onClick = function () {
openURL('www.paypal.me/aiscripts');
win.close();
}
win.center();
if (win.show() == 2) {
//alert("Cancelled");
return null;
} else {
return chk.value;
}
function openURL(address) {
var f = File(Folder.desktop + '/aiOpenURL.url');
f.open('w');
f.write('[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r');
f.close();
f.execute();
f.remove();
};
}
To test:
1. Create textframe in the Illustartor with content XXXX
2. Run the script
3. Result : The old content of the textframes that matched XXXX will get replace with 'NEW YORK'.
Let us know if this works for you.