in extendscript - Photoshop, dialog-box persistence?

笑着哭i 提交于 2021-01-29 04:15:09

问题


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


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/42217180/in-extendscript-photoshop-dialog-box-persistence

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