Another approach would be to set global variables to capture the dialog results at the top of the script. This example is a dialog but you should be able to adapt it for a palette that is listening for results.
The yres variable gets the result of the yellow dropdown, and mres gets the result of the magenta dropdown, then I run helper functions based on the results. The setExport() function calls the setup and export and it can be undone:
//results as global variables
var yres, mres, dlist;
makeDialog();
function makeDialog(){
var d = app.dialogs.add({name:"Export Layers", canCancel:true});
with(d){
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Yellow:"});
staticTexts.add({staticLabel:"Magenta:"});
}
with(dialogColumns.add()){
dlist = ["dont export", "as specified (visible + printable)", "as unprintable", "as hidden", "as hidden+unprintable"]
yres = dropdowns.add({stringList:dlist, selectedIndex:0, minWidth:80});
mres = dropdowns.add({stringList:dlist, selectedIndex:0, minWidth:80});
}
}
if(d.show() == true){
//get the dialog result or with a panel listen for results
yres = yres.selectedIndex;
mres = mres.selectedIndex;
//do onResult which calls the setters and export
app.doScript(setExport, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, 'Export Doc');
//undo the onResult function
app.activeDocument.undo();
}
}
}
function setExport(){
//set yellow
if (yres == 0) {
deleteLayer("Yellow")
} else if (yres == 1) {
alert("Do Nothing with Yellow")
}else if (yres == 2) {
noPrint()
}else if (yres == 3) {
hideNoPrintAll()
}
//app.activeDocument.pages.item(0).rectangles.add();
//setter here for magenta choice then export
//export routine here
alert("Export")
}
////////////////Settings Functions////////////////
function deleteLayer(ln){
alert("Deleting " +ln)
var y = app.activeDocument.layers.itemByName("Yellow")
if (y.isValid) {
y.remove()
}
}
function noPrint(){
alert("Set Layers to No Print")
}
function hideAll(){
alert("Set Layers to Hidden")
}
function hideNoPrintAll(){
alert("Set Layers to Hidden")
}
... View more