You can store data in an app label -- as Brian suggests -- but I prefer to write it to a file because I use scripts in three or more versions of InDesign. Using app. labels wouldn't work very well then. Another advantage of using a file is that the content is easier to inspect and easier to reset/delete/change manually.
I use this genelal schema for working with config files. The config file is names after the script (so abc.jsx creates a config file abc.txt) and is stored in the script's folder. You can use a separate Reseources folder, that's probably neater.
The below script stores the window's location, but also the content of the two text fields. You can store anything you like: location, size (in case of resizeable windows), selected items in lists, selected radiobuttons and checkboxes, etc. etc. And restore the window's slections.
The file that's created looks like this:
({location:[317, 385], first:"Piet", last:"Vlerk"})
Here's the script:
function scriptPath () {
try {
return app.activeScript;
} catch (e) {
return File (e.fileName);
}
}
// Write the config file
function saveData (obj) {
var f = File (scriptPath().fullName.replace (/\.jsx?(bin)?$/, '.txt'));
f.open ('w');
f.write (obj.toSource());
f.close ();
}
// Read the config file
function getPrevious () {
var f = File (scriptPath().fullName.replace (/\.jsx?(bin)?$/, '.txt'));
try {
return $.evalFile(f);
} catch (_) {
return null;
}
}
var w = new Window ('dialog');
w.firstName = w.add ('edittext {characters: 10}');
w.lastName = w.add ('edittext {characters: 10}');
w.add ('button {text: "OK"}');
w.add ('button {text: "Cancel"}');
w.onShow = function () {
// Look for the config file
var previous = getPrevious();
// It was there, populate window
if (previous !== null) {
w.location = previous.location,
w.firstName.text = previous.first,
w.lastName.text = previous.last
}
w.firstName.active = true;
}
// OK clicked: store the window data
if (w.show() === 1) {
saveData ({
location: [w.location.x, w.location.y],
first: w.firstName.text,
last: w.lastName.text
});
}