Running Find/Change queries via dialog window
Hi everyone,
I'm working on a script which runs Find/Change queries via a dialog window where each query has its own painel/button. The thing is that, only the 1st button works and when I click on it, it runs 'query 3' instead of 'query 1'. When I close the window, the script still runs 'query3', something that it's not supposed to do. I assume there are issues with 'myWindow.close' and 'myWindow.show'? Should I use another structure for the Find/Change function codes (e.g.: starting with If(...) etc.)?
See below a short version of the script - the final version will have several queries and lots of formatting attributes to Find/Change in the code. For now, I just need to figure out how to fix the mentioned issues. Could anyone please help me? Thanks in advance, Rogerio.
// My dialog window
var myWindow = new Window("dialog", "Title");
myWindow.text = "Find/Change Queries";
myWindow.preferredSize = [300,300];
myWindow.alignChildren = ["center","center"];
myWindow.orientation = "column";
myWindow.spacing = 5;
myWindow.margins = 15;
// Create panels and buttons
var panel1 = myWindow.add("panel");
panel1.text = "Query description 1"
var query1 = panel1.add("button", undefined, "Run query 1");
panel1.spacing = 10;
panel1.margins = 20;
var panel2 = myWindow.add("panel");
panel2.text = "Query description 2"
var query2 = panel2.add("button", undefined, "Run query 2");
panel2.spacing = 10;
panel2.margins = 20;
var panel3 = myWindow.add("panel");
panel3.text = "Query description 3"
var query3 = panel3.add("button", undefined, "Run query 3");
panel3.spacing = 10;
panel3.margins = 20;
// Query 1
query1.onClick = function() {
myWindow.close();
}
myWindow.show();
main();
function main(){
var doc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "Grep expression 1";
app.changeGrepPreferences.horizontalScale = 88;
app.changeGrepPreferences.verticalScale = 88;
app.findChangeGrepOptions.includeMasterPages = true;
doc.changeGrep();
}
// Query 2
query2.onClick = function() {
myWindow.close();
}
myWindow.show();
main();
function main(){
var doc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "Grep expression 2";
app.changeGrepPreferences.horizontalScale = 89;
app.changeGrepPreferences.verticalScale = 89;
app.findChangeGrepOptions.includeMasterPages = true;
doc.changeGrep();
}
// Query 3
query3.onClick = function() {
myWindow.close();
}
myWindow.show();
main();
function main(){
var doc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "Grep expression 3";
app.changeGrepPreferences.horizontalScale = 90;
app.changeGrepPreferences.verticalScale = 90;
app.findChangeGrepOptions.includeMasterPages = true;
doc.changeGrep();
}