Thanks @rob day this works great and is alot faster but I am getting the error below – although the error didnt show up the first few time i ran it and the script still works?
JavaScript Error!
Error Number: 2
Error String: tf is undefined
Engine: main
File: Path to script
Callout findReplace.jsx
Line: 32
Source: tf[jl.parentStory.changeGrep;
Being able to undo the whole script in one go is a great addition.
Hey - I think this might fix it - sorry don't have time to test it properly
// Undo the script if needed
app.doScript(searchCallout, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Search Callout');
function searchCallout() {
var res = getTextSearch("CALLOUT");
var pg, tf;
for (var i = 0; i < res.length; i++) {
// Check if the result has parent text frames and if its parent is a group
if (res[i].parentTextFrames.length > 0) {
pg = res[i].parentTextFrames[0].parent;
if (pg.constructor.name == "Group") {
tf = pg.textFrames.everyItem().getElements();
if (tf.length > 0) {
app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
for (var j = 0; j < tf.length; j++) {
app.findGrepPreferences.findWhat = "(was \\$\\d+(\\.\\d{2})? now \\$\\d+(\\.\\d{2})?)\\s";
app.changeGrepPreferences.changeTo = "";
tf[j].parentStory.changeGrep();
}
}
}
}
}
}
function getTextSearch(f) {
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findChangeTextOptions.properties = { includeHiddenLayers: true, includeLockedLayersForFind: true, includeLockedStoriesForFind: true, includeMasterPages: true };
app.findTextPreferences.findWhat = f;
return app.activeDocument.findText();
}