Hi Mike,
Here is something that might get you, or someone else started.
It's not _the_ solution, it has flaws but should get you started.
You could consider having the script add an xml tag to each found profanity, and then after the script is run, go through all the xml tags manually.
But hey, have a go and see what you can make of it.
This script requires you to have a list of all the profanities in a text file, one profanity on each line.
Hope it's helpfull in some way.
#targetengine "session"
// This script has one major flaw - you can not zoom or center the screen on the selection ...
var curItem = 0;
var myFoundItems = new Array ();
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
main();
} else {
alert("Please open a document");
exit();
}
var win = new Window( "window", "Browse items" );
win.myPanel = win.add("panel");
win.myPanel.myGroup = win.myPanel.add('group');
win.myPanel.myGroup.leftButton = win.myPanel.myGroup.add("button", undefined, "<-");
win.myPanel.myGroup.rightButton = win.myPanel.myGroup.add("button", undefined, "->");
win.myPanel.mySecGroup = win.myPanel.add('group');
win.myPanel.mySecGroup.doneButton = win.myPanel.mySecGroup.add("button", undefined, "Done");
myDocument.select(myFoundItems[0]);
win.myPanel.myGroup.rightButton.onClick = function() {
if (curItem == myFoundItems.length-1) {
curItem = 0;
myDocument.select(myFoundItems[curItem]);
// implement zoom
} else {
curItem = curItem+1;
myDocument.select(myFoundItems[curItem]);
// implement zoom
}
}
win.myPanel.myGroup.leftButton.onClick = function() {
if (curItem == 0) {
curItem = myFoundItems.length-1;
myDocument.select(myFoundItems[curItem]);
// implement zoom
} else {
curItem = curItem-1;
myDocument.select(myFoundItems[curItem]);
// implement zoom
}
}
win.myPanel.mySecGroup.doneButton.onClick = function() {
this.window.hide();
}
win.center();
win.show();
function main() {
try {
var script = app.activeScript;
} catch(err) {
var script = File(err.fileName);
}
var myScriptFolderPath = script.path;
var myFindChangeFile = File.openDialog("Choose the file containing the profanities (one word each line"); //new File(myScriptFolderPath + "/profanities.txt");
//alert(myFindChangeFile)
myFindChangeFile = File(myFindChangeFile);
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Loop through the find/change operations.
do {
//read 1 line into myLine
myLine = myFindChangeFile.readln();
//alert(myLine);
doSearchAndReplace(myLine, app.activeDocument);
} while(myFindChangeFile.eof == false);
myFindChangeFile.close();
// reset search
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
}
//alert(myFoundItems.length);
if (myFoundItems.length < 1) {
alert("No matches found!");
exit();
}
}
function doSearchAndReplace(stringfind, searchin) {
app.findTextPreferences.findWhat = stringfind;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = true;
myFoundItems = myFoundItems.concat(searchin.findText()); //.push(myNewFoundItems.slice(0, myFoundItems.length-1));
}
// Function By Dave Saunders - http://jsid.blogspot.com
function zoomObject(theObj) {
try {
var objBounds = theObj.geometricBounds;
} catch (e) {
throw "Object doesn't have bounds."
}
var ObjHeight = objBounds[2] - objBounds[0];
var ObjWidth = objBounds[3] - objBounds[1];
var myWindow = app.activeWindow;
var pageBounds = myWindow.activePage.bounds;
var PgeHeight = pageBounds[2] - pageBounds[0];
var PgeWidth = pageBounds[3] - pageBounds[1];
var hRatio = PgeHeight/ObjHeight;
var wRatio = PgeWidth/ObjWidth;
var zoomRatio = Math.min(hRatio, wRatio);
app.select(theObj); // to make active the page that holds theObj
myWindow.zoom(ZoomOptions.fitPage);
myWindow.zoomPercentage = myWindow.zoomPercentage * zoomRatio;
exit() // Because there's no point in doing this if you don't exit to let the user see
}
--
Thomas B. Nielsen
http://www.lund-co.dk