Discussion of the xtools Toolkit

Moderators:xbytor, DavideBarranca, Paul MR


Post by HiKO » Sun Jan 03, 2010 4:00 pm

Does anyone know how to write the from a user changed variables back to the INI-File?
E.g.: Preset of a Inputfield is 3, user change it to 4.
Next time if the user runs the script again it will start with 4 and
so on...

Thanks a lot - Regards,



Post by xbytor » Tue Jan 05, 2010 2:15 am

The general usage pattern is this:
1) Read the ini values from the file.
2) Set defaults if values are missing from the ini file.
3) Use the ini object to create the UI.
4) After the user has pressed the OK key (or whatever), read the values from
the UI and place them in an ini object.
5) Validate the values in the ini object.
6) If the ini values are valid, save the ini back to disk
7) Do your processing with the ini object.



Post by HiKO » Tue Jan 05, 2010 10:23 am

Hi X-bytor,

thx for reply. Point 1-4 I got in my script from your great example-INI-File.
I think the steps I have understood but can please help me a little bit with the coding stuff for step 5-7.
I couldn’t find it in the example of the INI-File.

Would be very great – thanks forward.
Greetz, HiKO



Post by HiKO » Thu Jan 14, 2010 5:02 pm

Hi – is this the right way to write back the changed variables:

// update ini file
var testINI = new File("~/Test.ini");
if ( testINI.exists ) {
obj.value1 = obj.value1,
obj.value2 = obj.value2,

// write the updates to the INI-File
IniFile.write("~/Test.ini", obj);

That’s happed before in the script – if the ini file doesn’t exist it will be created with preset values:

// write default settings to ini file
var testINI = new File("~/Test.ini");
if ( !testINI.exists ) {
var obj = {
value1: "24",
value2: "false",
// write presets to the INI-File
IniFile.write("~/Test.ini", obj);

It seems to be work!

Greetings, HiKO



Post by xbytor » Fri Jan 15, 2010 9:29 pm

This is extracted from a script I wrote few years ago. It may or may not run, but it should get the point across.

Code: Select allPrintLayoutOptions = function() {
  var self = this;
  self.sourceA    = PrintLayoutOptions.SOURCEA_DEFAULT;
  self.sourceB    = PrintLayoutOptions.SOURCEB_DEFAULT;
  self.outfolder  = PrintLayoutOptions.OUTFOLDER_DEFAULT;
  self.mode       = PrintLayoutOptions.ONE_UP;
  self.outputMode = PrintLayoutOptions.DEF_OUT_MODE; // "jpg","pdf,"psd"
PrintLayoutOptions.SOURCEA_DEFAULT   = "/c/work/dawn/printLayout/src/set1";
PrintLayoutOptions.SOURCEB_DEFAULT   = "/c/work/dawn/printLayout/src/set2";
PrintLayoutOptions.OUTFOLDER_DEFAULT = "/c/work/dawn/printLayout/pages";
PrintLayoutOptions.ONE_UP       = 'one';
PrintLayoutOptions.TWO_UP       = 'two';
PrintLayoutOptions.SIX_UP       = 'six';
PrintLayoutOptions.DUAL         = 'dual';

PrintLayoutOptions.DEF_OUT_MODE   = "pdf";

PrintLayoutOptions.INI_FILE = "~/printlayout.ini";

function main() {
   // create an object with the default options
   var opts = new PrintLayoutOptions();
   // load options from an ini file, overriding any defaults, opts);

   // later, after changing the opts as needed, write the new opts back out
   IniFile.write(PrintLayoutOptions.INI_FILE, opts);


Post Reply