1

in extendscript - Photoshop, I would like my dialog-box check boxes to default to previously used choices ... anyone know if this is possible?

B.B.
  • 11
  • 1

3 Answers3

3

You have two choices.

First choice: Using a //@targetengine

Values can be made persistent over a session using a targetengine.

First script

//@targetengine myengine
var x = 100;

Second script

//@targetengine myengine
$.writeln(x);

If you close Photoshop all of the values will be lost

Second choice: Write to a file.

I wont write an example here. This can be done in so many ways. Plain .txt file. .json file. See this example on how to read and write files.

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
0

fabianmoronzirfas has got the right answer. I will say it could with one script only. That script reads in the previous value stored in a text file in a hardcoded location like C:\temp. If the script cannot file the settings file it'll default to some predetermined value and then store this time around.

Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
0

Just in case, here is the simple script that saves (and tries to load) your prefs in JSON format to the system temp folder:

// set default values
var prefs = {
    file: File(Folder.temp.fsName + "/prefs.json"),
    title: "",
    length: 0
}

// try to load previous prefs
if (prefs.file.exists) prefs = $.evalFile(prefs.file);

// do something
prefs.title = prompt("Type the title:", prefs.title);
prefs.length = prefs.title.length;

// save the prefs to the file
prefs.file.open("w");
prefs.file.write(prefs.toSource());
prefs.file.close();
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23