skip to Main Content

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

3

Answers


  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.

    Login or Signup to reply.
  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.

    Login or Signup to reply.
  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();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search