Skip to main content
Inspiring
April 13, 2020
Question

UI Script Remember Last User Value Entered

  • April 13, 2020
  • 5 replies
  • 3186 views
The UI has 4 radio buttons and 4 editable text input fields. The editable fields have a default value "Edit Text". The objective is that the user enters a custom value in the text input field and runs the script.  

 

 

1)  Can a jsx script remember the last text input value used so that the next time the UI dialog runs the value appears in the text input field?
2) Allow the user to reset the dialog text input field to the default value.
3) What are the jsx functions that allow this behavior?

 

The idea is:
if the text input value is not equal to the default value,
the new text input value becomes a temporary variable,
the temporary variable becomes the default text input value,
then the user clears the temporary variable,
if the temporary variable is empty,
the script returns to the default text input value
This topic has been closed for replies.

5 replies

Legend
June 24, 2020

I do this by saving an XML file with settings, that way I can store whatever I want. Defaults are hard-coded.

PECourtejoie
Community Expert
Community Expert
April 13, 2020

Hello, I'm not sure if the file info part of Photoshop is a JSX found somewhere, but they implemented the same function recently.

 

Legend
April 13, 2020

//input variables
var settingsNameUniqueString = 'your script name',
text1 = 'sample text 1',
text2 = 'sample text 2',
text3 = 'sample text 3'

//saving settings
var d = new ActionDescriptor
d.putString (s2t('t1'), text1)
d.putString (s2t('t2'), text2)
d.putString (s2t('t3'), text3)
app.putCustomOptions (settingsNameUniqueString, d)

//reading settings
var d = app.getCustomOptions (settingsNameUniqueString)
alert (d.getString (s2t('t1')))
alert (d.getString (s2t('t2')))
alert (d.getString (s2t('t3')))

function s2t(s) { return app.stringIDToTypeID(s) }

ajabon grinsmith
Community Expert
Community Expert
April 13, 2020

This will remain even if you restart InDesign.

//save
app.insertLabel("foo", myString);
//load
var myString = app.extractLabel("foo");
Inspiring
April 13, 2020

Thank you will try in Photoshop.

ajabon grinsmith
Community Expert
Community Expert
April 13, 2020

I'm very sorry, I mistaken for InDesign because I had multiple windows open.
I don't think there is any other function that can hold the value even after restarting the application. It may be necessary to read / write to a text file with invisible attributes.

By the way, to get the action set and the action name surely, the description by the action descriptor obtained by ScriptListener should be indispensable.

Kukurykus
Legend
April 13, 2020

Play with putCustomOptions(), getCustomOptions() and eraseCustomOptions().

Inspiring
April 13, 2020

Thank you for providing the functions. Can the getCustomOptions() get the name of an action Set and action from the Actions Pallet?

Legend
April 13, 2020

Look at the scripts that come with Photoshop. Getting list of actions is well written in the image processor.jsx