B.B.
B.B.

Reputation: 11

in extendscript - Photoshop, dialog-box persistence?

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

Upvotes: 1

Views: 367

Answers (3)

Yuri Khristich
Yuri Khristich

Reputation: 14502

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();

Upvotes: 0

Ghoul Fool
Ghoul Fool

Reputation: 6949

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.

Upvotes: 0

fabianmoronzirfas
fabianmoronzirfas

Reputation: 4121

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.

Upvotes: 3

Related Questions