Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
One can create a txt or xml file to store the value/s and have the Script read the file on its next run.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
If you need a unique UUID for use with get/putCustomObjects go here:
Copy link to clipboard
Copied
Should the CustomOptions key be random? Or is it automatically generated?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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"
Find more inspiration, events, and resources on the new Adobe Community
Explore Now