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

牧云@^-^@ 提交于 2021-01-29 15:31:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/63213878/save-indesign-scriptui-options-in-file-and-load-in-the-next-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!