Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How to make a checkbox using javascript

Community Beginner ,
Sep 24, 2020 Sep 24, 2020

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();

TOPICS
Scripting
724
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
Sep 24, 2020 Sep 24, 2020

 

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();

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 25, 2020 Sep 25, 2020
LATEST

That's perfect, thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines