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

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

Community Expert ,
May 15, 2020 May 15, 2020

Copy link to clipboard

Copied

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;
        }

 

 

 

TOPICS
Scripting

Views

1.9K

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

Guide , May 18, 2020 May 18, 2020

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

Votes

Translate

Translate
Community Expert ,
May 16, 2020 May 16, 2020

Copy link to clipboard

Copied

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;
	}

 

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
Community Expert ,
May 18, 2020 May 18, 2020

Copy link to clipboard

Copied

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? 

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
Community Expert ,
May 18, 2020 May 18, 2020

Copy link to clipboard

Copied

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

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 ,
May 18, 2020 May 18, 2020

Copy link to clipboard

Copied

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

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
Community Expert ,
May 18, 2020 May 18, 2020

Copy link to clipboard

Copied

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.  

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
Community Expert ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

LATEST

For posterity, using app.activate() worked. The background application flickers, but then ID comes back. 

Also, I found out the client was using Windows Remote Desktop, which may have contributed to the problem. Also, if they minimized the other apps, they did not flicker. 

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