Skip to main content
Inspiring
November 15, 2014
Question

How to save input values in a dialog?

  • November 15, 2014
  • 3 replies
  • 1523 views

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!

This topic has been closed for replies.

3 replies

bagonterman
Inspiring
May 24, 2016

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"

DBarranca
Legend
November 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

Inspiring
November 15, 2014

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

UUID (GUID) Generator on the WEB

c.pfaffenbichler
Community Expert
Community Expert
November 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 ?