How to make a checkbox using javascript
Copy link to clipboard
Copied
I have a script that will create an array of all open documents, then it will display each document with a checkbox next to it. I don't know what to do know though. I don't know how to get the script to do something with the checked documents. My goal is to have the checked documents remain open, and the rest get closed without saving. Here is my code so far
var docNames = [];
for(i = app.documents.length-1; i>-1; i--) {
app.documents[app.documents.length-1].activate();
var currentDocName = app.activeDocument.name.replace(".ai","");
docNames.push(currentDocName);
}
var win = new Window ("dialog{text:'Which files to close?'}");
for(j = 0; j < docNames.length; j++){
win.abc = win.add ("checkbox", undefined, docNames[j]);
}
win.quitBtn = win.add ("button", undefined, "OK");
win.defaultElement = win.quitBtn;
win.show();
Explore related tutorials & articles
Copy link to clipboard
Copied
var win = new Window ("dialog{text:'Which files to close?'}");
var checkboxes = [];
var names = [];
for (var i = app.documents.length - 1; i > -1; i--){
names[i] = app.documents[i].name;
checkboxes[i] = win.add ("checkbox", undefined, names[i]);
}
win.quitBtn = win.add ("button", undefined, "OK");
win.defaultElement = win.quitBtn;
for (var j = 0; j < checkboxes.length; j++) {
(function (j) {
checkboxes[j].onClick = function () {
app.documents[names[j]].close();
};
})(j);
}
win.show();
Copy link to clipboard
Copied
That's perfect, thank you!

