Focus on previous app in OSX


I’m using app.dock.hide() and showing and hiding the Electron window with shortcuts.

When showing the Electron window it gets the OS focus (even if this is hidden with app.dock.hide()) so the app that was previously focused (eg: Finder or Chrome) loses the focus.

After I’m done with the Electron window I hide it, and I’d like to focus back on the app that had focus before Electron.

Is there a way to do that?

Returning focus to previously-focused window on hide

I’m having the same issue here. I’ve got a modal window that I bring up when I hit a global shortcut. When I hide the window (I’ve got a handler on the Esc key for this), I’d like to return the focus to whatever window was focused before (basically “returning” the focus).

Right now, if I’ve got a window open in my app, but I’m focused on another app, when I open and close my modal, focus goes to the window in my app, instead of being returned to the originally focused app. This means that my app pops up all the time, which is distracting.

Is there any way to return focus to the previously focused app?


hi guys, you can wrie a small applescript like
’tell application "System Events"
set activeApp to name of first application process whose frontmost is true
end tell
activate application activeApp’
there is an npm package to run applescript
this will do the trick !(it did for me)