Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I bring an OSX app to the front?

I'm working on a small, OSX app (it's a menubar app). When I initially build/launch the app, it goes to the foreground and all other apps go to the background (as they should). When I click on another app, that app comes forward and my app goes back (as it should), but when I click back on my app, it doesn't come forward again. The other app stays as the front-most app (regardless of what that other app is).

The big problem with this, aside from it just being weird, is that none of the hover actions or cursors work on my app when it is not the frontmost app.

Is there a way to programmatically force it to the front? How come clicking on it doesn't bring it forward?...

like image 762
Troy Avatar asked Dec 14 '22 15:12

Troy


1 Answers

I found the answer in this question. It can be done using either this:

[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];

or this:

[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
like image 106
Troy Avatar answered Dec 23 '22 10:12

Troy