Focus plugin window on open?

I’d like my plugin to be interacted with primarily via the keyboard.

The primary flow would be CMD+/, select plugin, down arrow to action in the plugin, return to run the action on the selected frame.

To do this, I need to set the user’s focus to the plugin window.

Is that possible?

Just call window.focus() in the UI code.

1 Like

Worked beautifully. Dead simple, can’t believe I didn’t try it. Thanks!

Apologies for asking in this solved thread. My question is kind of related to this.

I can’t manage to get the opposite work. Does window.blur() also work?

figma shortcuts doesn’t seem to work after an action made in the plugin. I added window.blur() inside an executed function (in UI code), but looks like the focus didn’t shift back to figma viewport. Any idea? Thanks

No, unfortunately the only way as far as I know it’s to click the canvas manually.

1 Like

That’s a shame. I guess I have to live with that for now. I hope figma will allow this someday.

I’ve seen your post here. I think that’s a great suggestion! but it’s been more than a year and no still change in Figma :confused:

Not sure it works everywhere but you can try this

@Gleb what do you think.

const focusFirstParentWithMoreThanOneFrame = () => {
  let parent = window.parent;
  while (parent.parent !== parent && parent.frames.length === 1) {
    parent = parent.parent;
  }
  parent.focus();
};

You don’t have access to outside frames with the Figma API sandbox limitations. Otherwise you would also be able to do a bunch of cool stuff like triggering shortcuts from a plugin.

I tried it in dev mode and it worked. Should try in production mode now

You cannot access elements in the iframe but looks like you might be able to run the focus function ?

Thanks for your feedback :slight_smile:

1 Like

That’s very cool, see the reply above ↑

I didn’t know it was possible, sorry for the misleading comment!

Your solution is even more elegant @tank666 ! Thaaaankkks guys :slight_smile: