Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to save input values in a dialog?

Participant ,
Nov 15, 2014 Nov 15, 2014

Hi there,

I've got the following dialog with an EditText in it:

var win, form; 

 

form = "dialog {  \ 

    orientation: 'column', \ 

    alignChildren: ['fill','top'], \ 

    preferredSize: [305, 300], \ 

    text: 'Form', \ 

    margins: 15, \ 

    input_group: Panel { \ 

        text: 'Number', \ 

        orientation: 'row', \ 

        alignChildren: ['fill','top'], \ 

        margins: 15, \ 

        input_obj: EditText { \ 

            text: '' \ 

        }, \ 

    } \ 

}" 

 

win = new Window(form);

Once the dialog is closed, I want it to save the EditText values, so when I open it again it already has it filled.

How do I create this behaviour?

Thanks!

TOPICS
Actions and scripting
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Nov 15, 2014 Nov 15, 2014

One can create a txt or xml file to store the value/s and have the Script read the file on its next run.

Re: WorkSpace Saver ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 15, 2014 Nov 15, 2014

Alternatively, you could use customOptions:

var win, form;   

   

form = "dialog {  \

    orientation: 'column', \

    alignChildren: ['fill','top'], \

    preferredSize: [305, 300], \

    text: 'Form', \

    margins: 15, \

    input_group: Panel { \

        text: 'Number', \

        orientation: 'row', \

        alignChildren: ['fill','top'], \

        margins: 15, \

        input_obj: EditText { \

            text: '' \

        }, \

    } \

    btn: Button { \

        text: 'Click me' \

    } \

}"   

win = new Window(form);

win.btn.onClick = function () {

    var desc = new ActionDescriptor();

    desc.putString(0, win.input_group.input_obj.text);

    app.putCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8", desc, true);

    win.close();

}

try {

    var desc = app.getCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8");

    win.input_group.input_obj.text = desc.getString(0);

} catch (e) {

    win.input_group.input_obj.text = "predefined value";

}

win.show();

Cheers,

Davide Barranca

---

www.davidebarranca.com

www.cs-extensions.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 15, 2014 Nov 15, 2014

If you need a unique UUID for use with get/putCustomObjects go here:

UUID (GUID) Generator on the WEB

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 15, 2014 Nov 15, 2014

DBarranca

Should the CustomOptions key be random? Or is it automatically generated?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 18, 2014 Nov 18, 2014

It needs to be a string, but the content is up to you ("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8" "is technically as OK as "ciao").

Usually you'd use a UUID because it's practically guaranteed it won't be duplicated within the PS register (please see xbytor link for a generator).

Davide Barranca

---

www.davidebarranca.com

www.cs-extensions.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 18, 2014 Nov 18, 2014

How to I access the registry? If I create an ID like this and Photoshop puts it in the registry, how can I then remove it? Is there a way?

I am about to update a couple of scripts with this, but while testing I wouldn't want Photoshop to remember all of these IDs, should I be concerned with managing them?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 18, 2014 Nov 18, 2014

How to I access the registry?

get/putCustomObjects as mentioned above.

how can I then remove it?

Do another putCustomOptions with your ID and either undefined or new ActionDescriptor(), I forget which.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 19, 2014 Nov 19, 2014

But is there a way for me to manually delete these registry entries? I will be doing  a couple of tests, is there a problem if the registry keeps all this data?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 24, 2016 May 24, 2016
LATEST

What I do for my InDesign scripts and it should work the same here is I will have the script rewrite itself every time it runs so the text in the script holds the data.

var schlNamePos = 54672 ;

    var updateFile = function(n){

    var f = File(app.activeScript);

    if ( f.open('e') ){

        f.seek(schlNamePos);

        f.write(''+n);

        f.close();

        }

    }

the top variable is the number of bytes in the script. It inserts the value from the dialog.

A way to get the insertion point is to delete everything up until that point and save a seperate script. Then run this script.

var myScript=File("/Applications/Adobe InDesign CC 2014/Scripts/Scripts Panel/Test/Test.jsx");

alert(myScript.length);

That will give you the number of bytes you have to seek into. ex: "54672"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines