Skip to main content
TheAzzam
Inspiring
September 19, 2022
Answered

Can't click on button in window created using ScriptUI

  • September 19, 2022
  • 1 reply
  • 721 views

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/SnpCreateDialog.jsx

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.
  @11203287 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();
}

 

This topic has been closed for replies.
Correct answer jazz-y

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.

1 reply

jazz-yCorrect answer
Legend
September 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.

TheAzzam
TheAzzamAuthor
Inspiring
September 19, 2022

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?
Legend
September 19, 2022

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.