Por favor, vea el código a continuación. Me gustaría tenerlo para que javascript recuerde el botón seleccionado desde la última vez que se ejecutó el script.
var doc = app.activeDocument; var choice; var w = new Window("dialog"); w.text = "Please Select Your Gemini Save Location Below"; var g = w.add("group"); var a = g.add("radiobutton", undefined, "MN"); var b = g.add("radiobutton", undefined, "WA"); var c = g.add("radiobutton", undefined, "CA"); var d = g.add("radiobutton", undefined, "TX"); var e = g.add("radiobutton", undefined, "Remote"); var button = w.add("button", undefined, "OK"); var radiobuttons = [a, b, c, d, e]; a.checkedState = true; for (var i = 0; i < radiobuttons.length; i++) { (function (i) { radiobuttons[i].onClick = function () { choice = radiobuttons[i].text; }; })(I); }w.mostrar();
Estoy acostumbrado a guardar preferencias en un archivo json y leerlas desde el archivo al comienzo de un script.
Para tu caso sería algo como esto:
var doc = app.activeDocument; // try to loads saved prefs or set default prefs var prefs = load_prefs() || {a: true, b:false, c:false, d:false, e:false, choice:'MN'} var choice = prefs.choice; // <-- get choice from prefs; var w = new Window("dialog"); w.text = "Please Select Your Gemini Save Location Below"; var g = w.add("group"); var a = g.add("radiobutton", undefined, "MN"); var b = g.add("radiobutton", undefined, "WA"); var c = g.add("radiobutton", undefined, "CA"); var d = g.add("radiobutton", undefined, "TX"); var e = g.add("radiobutton", undefined, "Remote"); var button = w.add("button", undefined, "OK"); // set the radiobutton from the prefs a.value = prefs.a; b.value = prefs.b; c.value = prefs.c; d.value = prefs.d; e.value = prefs.e; var radiobuttons = [a, b, c, d, e]; for (var i = 0; i < radiobuttons.length; i++) { (function (i) { radiobuttons[i].onClick = function () { choice = radiobuttons[i].text; }; })(i); } w.show(); alert(choice); // set the prefs from radiobuttons prefs.a = a.value; prefs.b = b.value; prefs.c = c.value; prefs.d = d.value; prefs.e = e.value; prefs.choice = choice; // <-- save choice save_prefs(prefs); // save the prefs // functions to load and save prefs function load_prefs() { var file = File(Folder.temp + '/prefs.json') return (file.exists) ? $.evalFile(file) : false; } function save_prefs(prefs) { var file = File(Folder.temp + '/prefs.json') file.open('w'); file.encoding = 'UTF-8'; file.write(prefs.toSource()); file.close(); }Por si acaso. Por supuesto, puede usar un bucle para configurar los botones de opción de preferencias y viceversa, si lo desea. Algo como esto:
// prefs var prefs = {a:true, b:false, c:false, d:false, e:false}; // radiobuttons var a = {}, b = {}, c = {}, d = {}, e = {}; // set radiobuttons from prefs var radiobuttons = {a,b,c,d,e}; for (var btn in radiobuttons) radiobuttons[btn].value = prefs[btn]; console.log(radiobuttons) // change values of some radiobuttons a.value = false; b.value = true; // set prefs from radiobuttons for (var pr in prefs) prefs[pr] = radiobuttons[pr].value; console.log(prefs)