Highlighted

How to make a checkbox using javascript

Community Beginner ,
Sep 24, 2020

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

TOPICS
How to, Scripting

Views

98

Likes

Translate

Translate

Report

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

How to make a checkbox using javascript

Community Beginner ,
Sep 24, 2020

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

TOPICS
How to, Scripting

Views

99

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 24, 2020 1
Engaged ,
Sep 24, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 24, 2020 2
Community Beginner ,
Sep 25, 2020

Copy link to clipboard

Copied

That's perfect, thank you!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 25, 2020 0