Skip to main content
brian_p_dts
Community Expert
Community Expert
May 15, 2020
Answered

Issue with Script UI Dialog button clicks causing previous application to load

  • May 15, 2020
  • 2 replies
  • 2330 views

Hi all - encountering a weird bug with a client. They are running Windows 10, and trying to execute a script that executes a variety of different dialogs. I'm using onClicks for the buttons. When they either use keystrokes or mouseclicks on the buttons, the script brings up the previously used application (ie, it makes Chrome the active application). I'm running these scripts on Mac Catalina, and not having this issue, nor did they have this issue running on InDesign CS6. It's only in their Windows 10 instance that's this happening. Has anyone experienced this before? Should I just use "1" and "2" results on the button clicks instead. Tough for me to test since I don't have Windows 10. Here's one sample dialog below. 

 

Thanks. 

 

 

 

var dialog = new Window("dialog"); 
	dialog.orientation = "column"; 
	dialog.alignChildren = ["center","top"]; 
	dialog.spacing = 10; 
	dialog.margins = 16; 
	dialog.text = "Test";

var statictext1 = dialog.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Change cell contents to " + short_code + "?"; 

    // GROUP1
    // ======
    var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.orientation = "row"; 
    group1.alignChildren = ["left","center"]; 
    group1.spacing = 10; 
    group1.margins = 0; 

	var button1 = group1.add("button", undefined, undefined, {name: "ok"}); 
							
		button1.text = cell_contents.contents.toUpperCase();
		button1.onClick = function() {
			dialog.close();
		}

	var button2 = group1.add("button", undefined, undefined, {name: "cancel"}); 
		button2.text = short_code;
		button2.onClick = function() {
		change_cell = true; 
	        dialog.close();
	}
							

	dialog.show();
	if (change_cell) {
	    the_cell.contents = short_code;
        }

 

 

 

This topic has been closed for replies.
Correct answer Dirk Becker

Have you tried "app.activate();"  ?

2 replies

Dirk BeckerCorrect answer
Legend
May 18, 2020

Have you tried "app.activate();"  ?

brian_p_dts
Community Expert
Community Expert
May 18, 2020

I have not. I was wondering if there was such a method in app. I started to look then got sidetracked. I'll give it a shot and report back. Thanks.  

Peter Kahrel
Community Expert
Community Expert
May 16, 2020

Your code work fine over here (on Windows 10). What your customer sees is probably a bug that was introduced in InDesign CC, where after a script that uses a ScriptUI dialog, after quitting the dialog, causes InDesign to lose focus, which brings the previous used application to the front. It's an INDesign thing, nothing to do with Windows

Some code changes may make a difference. If you test user response and change the code inside the dialog, things are easier (a bit more intuitive):

	var button1 = group1.add("button", undefined, undefined, {name: "cancel"}); 
		button1.text = cell_contents.contents.toUpperCase();

	var button2 = group1.add("button", undefined, undefined, {name: "ok"}); 
		button2.text = short_code;

	if (dialog.show() === 1) {
		the_cell.contents = short_code;
	}

 

brian_p_dts
Community Expert
Community Expert
May 18, 2020

Thanks, Peter. Switching to checking the result integer of dialog.show() didn't help, unfortunately. It's so strange that it only happens on certain computers (not on yours, not on mine). Have you ever thought up other workarounds? Having other apps closed? A VBA perhaps called to restore focus? 

Peter Kahrel
Community Expert
Community Expert
May 18, 2020

I don't know of any workaround. The VBA route looks too painful to me. Sorry.