refocussing a window

I have an app that is set with NSUIElement at 1 to not show the dock icon. This all works fine except that when I want a window to reappear from hidden state it is never really selected. Though the window is frontmost, I need to click on it first to start enetering text.

I tried different approaches (all from here) to solve this but to no avail. Any ideas on what I can do?