Skip to main content
Participant
March 1, 2019
Answered

ScriptUI Palette Focus After Clicking Button

  • March 1, 2019
  • 2 replies
  • 2898 views

Hello, first time poster here!

I am working on developing an InDesign palette and I have run into an issue surrounding clicking buttons. The palette that I am working on is something that I want to stay open so that the user can interact with it while they work on their InDesign document. I want key focus to be on the document after clicking buttons in the palette and I am a bit stuck.

Here is my use case: I click a button in the palette and it selects multiple frames on the page. I then want to be able to use arrow keys to nudge the frames around (for example). I can’t use the arrow keys to move the objects until I click back into the document because the palette is holding key focus.

How do I tell my script to return focus to the InDesign document while keeping the palette open?

Any feedback is appreciated!

Thanks,

Jeremy

This topic has been closed for replies.
Correct answer Marc Autret

Hi Jeremy,

(…)

How do I tell my script to return focus to the InDesign document while keeping the palette open?

Invoke app.activate() whenever you need to give the focus back to InDesign.

Something like this:

myButton.onClick = function onClickHandler()

{

app.select( app.activeDocument.spreads[0].pageItems.everyItem().getElements() );

app.activate();

};

Best,

Marc

2 replies

Inspiring
December 27, 2020

Sorry for digging up such an old thread, but the answer Marc provided doesn't work for me either (nor Chris' tip with app.selection = null). With an open panel, app.activate() doesn't do anything on the Mac. Hope it's not just a bug.

 

Thanks!

Inspiring
December 18, 2022

I can confirm this (non-)behaviour for Mac even all the years after the original post. Please vote on uservoice:

https://indesign.uservoice.com/forums/601180-adobe-indesign-bugs/suggestions/46096285-scirptui-in-events-app-activate-doesn-t-work

Marc Autret
Marc AutretCorrect answer
Legend
March 1, 2019

Hi Jeremy,

(…)

How do I tell my script to return focus to the InDesign document while keeping the palette open?

Invoke app.activate() whenever you need to give the focus back to InDesign.

Something like this:

myButton.onClick = function onClickHandler()

{

app.select( app.activeDocument.spreads[0].pageItems.everyItem().getElements() );

app.activate();

};

Best,

Marc

Participant
March 1, 2019

I tried that but it's not working as expected. Here is a dummy script that I set up to test that approach:

#targetengine 'session'

var myDoc = app.activeDocument;

var myTextFrame = myDoc.textFrames[0];

var myDialog = new Window ("palette","Layers",undefined, {resizeable:true});

myDialog.preferredSize = [300,300];

var selectButton = myDialog.add("button", undefined, "Select The Things");

selectButton.onClick = function (){

    app.selection = myTextFrame;

    app.activate();

    };

myDialog.show();

app.activate();

Marc Autret
Legend
March 2, 2019

Well your dummy script works for me :-/

The app recovers the focus and I can move the text frame using arrow keys…

Tested on Win10 with ID 14.0.

Maybe a Mac issue (?)

@+

Marc