Copy link to clipboard
Copied
Hi everyone,
I'm looking for an elegant way to store the value changes on a script ui from one use to another.
Here is a simple example, how to get the same value back for checkboxes and editable text.
// ======
var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
var checkboxA = group1.add("checkbox", undefined, undefined, {name: "checkboxA"});
checkboxA.text = "A";
checkboxA.value = true;
var checkboxB = group1.add("checkbox", undefined, undefined, {name: "checkboxB"});
checkboxB.text = "B";
checkboxB.value = true;
var checkboxC = group1.add("checkbox", undefined, undefined, {name: "checkboxC"});
checkboxC.text = "C";
checkboxC.value = false;
var checkboxD = group1.add("checkbox", undefined, undefined, {name: "checkboxD"});
checkboxD.text = "D";
checkboxD.value = false;
var checkboxE = group1.add("checkbox", undefined, undefined, {name: "checkboxE"});
checkboxE.text = "E";
checkboxE.value = false;
// DIALOG
// ======
var edittext1 = dialog.add('edittext {properties: {name: "edittext1"}}');
edittext1.text = "my text 1";
var launchButton = dialog.add("button", undefined, undefined, {name: "launchButton"});
launchButton.text = "launch";
launchButton.onClick = function(){
//do stuff
dialog.close();
};
dialog.show();
I' m actually doing the job with another .jsx wher i store the values.
//version to manage the pref file
prefVersion = 1.00
//check if the pref file is up to date
prefFile = new File(Folder.myDocuments + "/myPref_" + prefVersion + ".jsx");
if (!prefFile.exists) {
var fileList = new Folder(Folder.myDocuments).getFiles();
for (var i = 0; i < fileList.length; i++) {
fileList[i].remove(); //erase the file if it is not up to date
}
}
// ========================================= UI
var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;
// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;
var checkboxA = group1.add("checkbox", undefined, undefined, {name: "checkboxA"});
checkboxA.text = "A";
checkboxA.value = false;
var checkboxB = group1.add("checkbox", undefined, undefined, {name: "checkboxB"});
checkboxB.text = "B";
checkboxB.value = false;
var checkboxC = group1.add("checkbox", undefined, undefined, {name: "checkboxC"});
checkboxC.text = "C";
checkboxC.value = false;
var checkboxD = group1.add("checkbox", undefined, undefined, {name: "checkboxD"});
checkboxD.text = "D";
checkboxD.value = false;
var checkboxE = group1.add("checkbox", undefined, undefined, {name: "checkboxE"});
checkboxE.text = "E";
checkboxE.value = false;
// DIALOG
// ======
var edittext1 = dialog.add('edittext {properties: {name: "edittext1"}}');
edittext1.text = "my text 1";
var launchButton = dialog.add("button", undefined, undefined, {name: "launchButton"});
launchButton.text = "launch";
launchButton.onClick = function(){
//do stuff
dialog.close();
};
//check if the pref file exist
if (!prefFile.exists) {
defaultPref();
}
// if not a pref file with default value is create
function defaultPref() {
var defaultValue = "prefVersion = 1.00; checkboxA.value = false; checkboxB.value = false; checkboxC.value = false; checkboxD.value = false; checkboxE.value = false; edittext1.text = \"my text 1\";";
prefFile.open('w');
prefFile.writeln(defaultValue);
prefFile.close();
return "defaultValueUP"
}
//include pref file
eval('#include' + prefFile.fullName);
dialog.show();
dialog.onClose = savePref();
//on close the pref file is updated
function savePref() {
var newValue = " checkboxA.value = " + checkboxA.value + "; checkboxB.value = " + checkboxB.value + "; checkboxC.value = " + checkboxC.value + "; checkboxD.value = " + checkboxD.value + "; checkboxE.value = " + checkboxE.value +"; edittext1.text = \"" + edittext1.text + "\" ;";
prefFile.open('w');
prefFile.writeln(newValue.toString());
prefFile.close();
}
Any idea ?
thanks 🙂
Teddy
Copy link to clipboard
Copied
A txt-file would do as well.
Another option would be using a custom namespace to store the settings, but I couldn’t find a more recent or pertinent thread than this one at current.
Copy link to clipboard
Copied
thx,
for sure, i will do it with a text file.
hmmm i don't really anderstand the the thread.
But to store the value in an object sounds like an elegant option. Is that what you are talking about ?
Copy link to clipboard
Copied
Either a text file or see if you can write to Preferences (which is possible in Bridge.)
app.preferences.myNamespace_.myPreference
Copy link to clipboard
Copied
Thx,
i don't know why i didn't simply create a text file ^^'
it'is not really pref but just UI values i want to store...