save InDesign ScriptUI options in file and load in the next run

425 views Asked by At

I built a Dialog in InDesign script that has any options.

I want to save the settings the user selects in a file (For example in a file named setting.ini) to do not require a re-adjustment in the next run and the same settings are enabled for the Dialog.

Is there such a possibility?

enter image description here

1

There are 1 answers

0
mdomino On BEST ANSWER

Yes, you can use the label functionality to save any information to any InDesign objects. To save things from dialogs that you want to access the next time that a script is run, it would make most sense to save the info into the app object directly, that way it will be available even after closing and re-starting InDesign (as opposed to saving it into a Document which might not be open the next time the users uses the script).

The general workflow would be something like this:

// after the user closes the dialog, save the settings they made to an object
var userChoice = {
  // save any info from the dialog, for example some settings about underlines
  underline: checkbox3.value,
  underlineWeight: edittext6.text,
  underlineOffset: edittext7.text,

  // etc. ...
};

// insert the given information into a script label, pick any arbitrary name
// use .toSource() to stringify the object in the process, labels can only save strings

app.insertLabel("ha_a_usersettings", userChoice.toSource());

Now the info is saved in the app itself. Next time you run the script, you can retrieve the information from the label like this:

var savedSettings = eval(app.extractLabel("ha_a_usersettings"));

Now you can proceed and pre-populate the dialog with the properties you have in the savedSettings variable.