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

Making ScriptUI Buttons Do Something

Community Expert ,
Jun 09, 2021 Jun 09, 2021

The scriptUI builder from Joonas has reduced the amount of time that it takes to create a GUI, which is fantastic.

 

Presuming that I have my code already working without a GUI, I am really struggling to work out how to test and link up a function or other "result" to the GUI elements in the window.

 

Take for example this code, it is a simple test, it only has two radio buttons and an OK and Cancel button.

 

myWindow.png

 

I have worked out how to test and return that it is "true" if a radio button is selected. This also works the same for checkboxes. All good so far.

 

However, I don't know what to do with the OK and cancel buttons. If I select a radio button and cancel, the function called by the button is executed. Obviously the expectation is that if cancel is pressed, then nothing happens.

 

Do I need to do anything for the OK button?

 

I am finding it hard looking at existing code and have not had much success with othe resources such as forum searches.

 

There must be a resource that simply explains this stuff with working examples? It is taking hours of research for me to get a UI element to do something correctly, so am I missing a basic resource?

 

This is of course just the start of my questions, there are many different UI controls (dropdowns, fields etc)... Which I'll get to.

TOPICS
Actions and scripting
5.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

correct answers 2 Correct answers

LEGEND , Jun 09, 2021 Jun 09, 2021

I was writing the answer before you posted the code:

 

// SHOW THE WINDOW

function yourCode() {
	function button1result() {
			alert("You selected Button 1");
	}

	function button2result() {
			alert("You selected Button 2");
	}

	if (radioButton1.value === true) {
			button1result();
	}

	if (radioButton2.value === true) {
			button2result();
	}
}

myDialogWindow.show() - 2 ? yourCode() : alert('Exit!')

 

Translate
LEGEND , Jun 25, 2021 Jun 25, 2021
dropdownMenu.selection.index
Translate
Adobe
LEGEND ,
Jun 26, 2021 Jun 26, 2021

You probably missed my correct answer in other post: Jun 25, 2021 🙂

Put that in place of buttonActions() function content and run the code.

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
Explorer ,
Jun 09, 2021 Jun 09, 2021

Don't forget that every form-item has a few methodes that deal directly with events. 
onActivate, onClick, onDeactivate and then some more. THese allow for more granular control of what your buttons and other elements do, for instance:

okButton.onClick = function(){

    var theText = "you chose option : " + dropDown.selection.index;

   alert(theText );

}
(more info per element here: https://theiviaxx.github.io/photoshop-docs/ScriptUI/index.html)
As far as I understand Cancel and Ok buttons have specific behavior, but these only pertain to the window, so any script that runs after the dialog closes runs regardless what is clicked (ok/cancel). What I tent to do to work around this is to have a variable "processed" setup as false before the dialog and have the ok-button onclick action change that to true:
var processed = false;
/* dialogwindow code */
buttonOK.onclick = function(){

     /* processing code */

    processed = true;

}

/* rest of code follows: */
if( processed == true ){

  /*application code */

} else {

 //do nothing

}

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
LEGEND ,
Jun 09, 2021 Jun 09, 2021

...and onDoubleClick for ListBox when using addEventListener to enrich a code even more 🙂

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