Can't click on button in window created using ScriptUI

Explorer ,
Sep 18, 2022 Sep 18, 2022

Copy link to clipboard

Copied

In Photoshop, using ExtendScript, I created a window using the code given in this link: https://github.com/Adobe-CEP/CEP-Resources/blob/master/ExtendScript-Toolkit/Samples/javascript/SnpCr...

However, I am unable to click on the buttons in the window created, nor does the window stay open without adding a sleep statement in the function. Any ideas?

/** 
  @fileoverview Shows how to create a basic ScriptUI dialog.
  @class Shows how to create a basic ScriptUI dialog.
 
  <h4>Usage</h4>
  <ol>
  <li>Run the snippet in the ExtendScript Toolkit (see Readme.txt).
     This snippet can run in any application that supports ScriptUI.
 <li>A dialog appears, which emits trace statements to the JavaScript console to indicate which button was pressed.
 </ol>
  
  <h4>Description</h4>
  <p>Creates and shows a simple ScriptUI modeless dialog (also called a palette)
  with OK/Cancel buttons and event listeners that implement the button behavior.<br ./>
  
  @constructor Constructor.
 */
function SnpCreateDialog() 
{
	this.windowRef = null;
}

/**
 Functional part of this snippet. 
 
 Create a window of type "palette" (a modeless dialog) and display it.
 @Return True if the snippet ran as expected, false otherwise.
 @TyPe Boolean
*/
SnpCreateDialog.prototype.run = function()
{
	// Create a window of type palette.
	var win = new Window("palette", "SnpCreateDialog",[100,100,380,245]);  // bounds = [left, top, right, bottom]
	this.windowRef = win;
	// Add a frame for the contents.
	win.btnPanel = win.add("panel", [25,15,255,130], "SnpCreateDialog");
	// Add the components, two buttons
	win.btnPanel.okBtn = win.btnPanel.add("button", [15,65,105,85], "OK");
	win.btnPanel.cancelBtn = win.btnPanel.add("button", [120, 65, 210, 85], "Cancel");
	// Register event listeners that define the button behavior
	win.btnPanel.okBtn.onClick = function() {
		$.writeln("OK pressed");
		win.close();
	};
	win.btnPanel.cancelBtn.onClick = function() {
		$.writeln("Cancel pressed");
		win.close();
	};

	// Display the window
	win.show();
		
	return true;
		
}

/**
 "main program": construct an anonymous instance and run it
  as long as we are not unit-testing this snippet.
*/
if(typeof(SnpCreateDialog_unitTest) == "undefined") {
    new SnpCreateDialog().run();
}

 

TOPICS
Actions and scripting , SDK , Windows

Views

60

Likes

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

Community Expert , Sep 19, 2022 Sep 19, 2022

Perhaps this worked in 2007, but now it doesn’t.

Check out the topic: How can Scriptui SnpCreateDialog.jsx be changed to make "palette" that doesn't disappear?  there is a solution that allows you to use the palette mode in current versions.

Likes

Translate

Translate
Community Expert ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

Perhaps this worked in 2007, but now it doesn’t.

Check out the topic: How can Scriptui SnpCreateDialog.jsx be changed to make "palette" that doesn't disappear?  there is a solution that allows you to use the palette mode in current versions.

Likes

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
Explorer ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

Yes, the code in the link does work. However, I'm having trouble understanding some lines of the code. Specifically this segment

(bt = new BridgeTalk()).target = 'photoshop'
bt.body = cnt(zooming_panel.toSource()), bt.send()
Can you help me understand it?

Likes

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
Community Expert ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

BridgeTalk is a module that allows you to send code between Adobe applications and run it in a separate thread. The code is sent as a string (roughly speaking, BridgeTalk receives the source code to be executed in the specified application). In this case, it specifies that the target application is Photoshop, then the source code for the zooming_panel function is placed in the BridgeTalk body (.toSource() is needed here to send the source code of the function as a string), followed by sending this message.

 

You can read chapter Interapplication Communication with Scripts in Javascript Tools Guide to get more info.

Likes

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
Explorer ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

For the life of me I cannot find out how to show a textbox and a button together, such that clicking the button shows the text entered in the textbox. This is my code so far:

function fnctn() {
	win = new Window('palette' , "PS Button Palette");
	function wa(v) {return win.add('button', undefined, v)}
    
	for(i = 0; i < (elements = ['Text', 'Close Palette']).length;){
		wa(elements[i++]).onClick = function() {
			if (this.text == 'Close Palette')  {win.close();}
			if (this.text == 'Text') 
            {
                win.close();
                text_win = new Window('palette', 'Text Palette');

                // Function to add textbox
                function textbox(v) {return text_win.add('edittext', undefined, v);}

                textbox('Enter text').onClick = function() {
                    alert(text_win.text);
                }
                text_win.show();
            }	
		}
	}
	win.show()
}

function cnt(v) {return 'fnctn = ' + v + '; fnctn()'}

(bt = new BridgeTalk()).target = 'photoshop' 
bt.body = cnt(fnctn.toSource()), bt.send()

Likes

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
Community Expert ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

I don't fully understand what you are trying to get as a result, however edittext does not support onClick()

2022-09-19_15-53-59.png

2022-09-19_15-54-10.png

Likes

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
Explorer ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

LATEST

I'm trying to show a text box along with an "OK" button, that returns the input fed into the text box when clicked. I have not been able to code this for the past two hours.

Likes

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

Save time with Adobe Express quick actions