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

How to save input values from text box?

Engaged ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

I searched here and saw a good example using customOptions.

 

 

Why does not my Photoshop recognize this string?

("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8")

 

How to find, get and validate these string so that it works perfectly?

I saw something here but it did not work in any key I generated.

uuidgen

 

Here is a small dialog box with two text boxes that I need to save the values whenever I need to open the window.

dlg = new Window("dialog", "new project", [0, 0, 255, 100], {resizeable: true});
text01 = dlg.add("edittext", {x: 26, y: 26, width: 48, height: 20}, "");
text02 = dlg.add("edittext", {x: 86, y: 26, width: 48, height: 20}, "");
var desc = app.getCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8");
text01.text = desc.getString(0); button = dlg.add("button", [162, 26, 232, 46], "Ok");

button.onClick = function() {
	var desc = new ActionDescriptor(); 
	desc.putString(0, text01.text); 
	app.putCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8", desc, true); 
}

dlg.center();
dlg.show();

Can anyone explain to me how this method works?

TOPICS
Actions and scripting

Views

2.3K

Translate

Translate

Report

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

correct answers 1 Correct answer

People's Champ , Sep 13, 2018 Sep 13, 2018

var desc = null;

try { desc = app.getCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8"); } catch (e) {};

if (desc) text01.text = desc.getString(0);

Votes

Translate

Translate
Adobe
People's Champ ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

var desc = null;

try { desc = app.getCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8"); } catch (e) {};

if (desc) text01.text = desc.getString(0);

Votes

Translate

Translate

Report

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 ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

Thank you r-bi.

It worked very well. Just a question. To add in other text boxes, do I have to have other individual character keys for each?

Votes

Translate

Translate

Report

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
People's Champ ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

In this way

var desc = null; 

try { desc = app.getCustomOptions("77F66FF5-EFAD-49B7-AFE3-8A1403376CB8"); } catch (e) {};  

if (desc)

    {

    text01.text = desc.getString(0);  

    text02.text = desc.getString(1);  

    text03.text = desc.getDouble(stringIDToTypeID("width"));  

    }

...................

................... 

 

        var desc = new ActionDescriptor();   

        desc.putString(0, text01.text);   

        desc.putString(1, text02.text);   

        desc.putDouble(stringIDToTypeID("width"), Number(text03.text));   

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

Votes

Translate

Translate

Report

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 ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

Thanks again! You are the greatest of all time.

Votes

Translate

Translate

Report

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
LEGEND ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

How to check custom option exists without try...catch statement?

 

Is there some ActionDescriptor key for?

 

Personally I found in 'C:\Users\Marek\AppData\Roaming\Adobe\Adobe Photoshop CS6\Adobe Photoshop CS6 Settings\Adobe Photoshop X64 CS6 Prefs.psp'

 

they are stored at the moment of quitting Photoshop, I mean their name after:

 

5d9bdc30-d980-4d66-92b8-3fdb0eb270c5

 

What is interesting when I did:

 

typeIDToStringID(getCustomOptions('5d9bdc30-d980-4d66-92b8-3fdb0eb270c5').getKey(0))

 

it showed me: 'javaScriptMessage'

 

 

The same you can find in the ScriptListenerJS.log code after running some script from File / Scripts:

 

(dsc = new ActionDescriptor()).putString(stringIDToTypeID('javaScriptName'), 'someItem')
dsc.putString(stringIDToTypeID('javaScriptMessage'), '''undefined''')
executeAction(stringIDToTypeID('AdobeScriptAutomation Scripts'), dsc, DialogModes.NO)

 

Votes

Translate

Translate

Report

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
Guide ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

I tried this code in several ways, but still did not understand how to check custom option exists in my scripts 😞

(dsc = new ActionDescriptor()).putString(stringIDToTypeID('javaScriptName'), 'someItem')
dsc.putString(stringIDToTypeID('javaScriptMessage'), '''undefined''')
executeAction(stringIDToTypeID('AdobeScriptAutomation Scripts'), dsc, DialogModes.NO)

This code simply runs the script, regardless of whether the settings were saved or not (the main thing is that the script is installed)

Votes

Translate

Translate

Report

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
LEGEND ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

I mentioned about this code only because this is only one where I found 'javaScriptMessage' string, but probably it's unrelated to the same string (wrote as posted 'number'). How custom options work you can find in several threads on this forum. My question is how to check by only ActionManager some custom option exists, or the length of them (eventually the key for is avialable).

 

Everything to get rid of try...catch statement. For example you can do the same to check if some file exists in file system, or if the background layer exists in document.

 

Normally such things people were doing by try...catch, but these days we know there is AM method for it too, similar one I'd like to get to know for custom options.

Votes

Translate

Translate

Report

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
Guide ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

@Kukurykus,i understand that this is not the best way, but what if you look for the header in the .psp file?

For example

 

(f = new File (app.preferencesFolder + '/Adobe Photoshop 2020 Prefs.psp')).open('r')
var s = f.read()
if (s.indexOf ('script name') !=-1)  alert ('here we go')

 

at the same time, if the settings name starts with a digit, then it will be preceded by

 

'atdt%\x00\x00\x00'

 

if the settings name begins with a letter, then it will be in front of it

 

'atdt\x0E\x00\x00\x00'

 

those,

 

if (s.indexOf ('atdt%\x00\x00\x00' + '3338481a-9241-4c33-956e-4088f660e936') !=-1)  alert ('here we go')
if (s.indexOf ('atdt\x0E\x00\x00\x00'+ 'TestSettings') !=-1)  alert ('here we go')

 

Votes

Translate

Translate

Report

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
LEGEND ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

Yes, that's something I found after my post myself shortly too. But in this case it's better to use still try...catch statement, however it won't list you all taken custom options. The other problem is this preferences file is resaving after quitting Photoshop, so that's good method only at launching Ps.

 

Later there came to me new, more interesting question about it. Where are stored all descriptors data (set as permanent by custom options) after quitting Ps. As you know you can retrieve them launching Photoshop again, so I'm curious where are they stored between sessions?

Votes

Translate

Translate

Report

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
Guide ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

In the same file I found the variable names from my scripts. Most likely the values themselves are stored there.

In addition, if you delete this file, then all saved values are lost.

Votes

Translate

Translate

Report

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
LEGEND ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

LATEST

I couldn't find them there. Could you create simple descriptor with some text inside, and show me where (beside custom option name) is everything a descriptor (held by custom option) includes?

 

Okey I found it, but I have no idea how 3 months ago I could miss other info than CO names 😕

Votes

Translate

Translate

Report

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