Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an About window the front-most window in a Cocoa application with no UI?

I'm building a Cocoa application that runs as an item in the status bar. This application has an About window and an item to activate that about window, using the standard Cocoa mechanism for doing so (-[NSApplication orderFrontStandardAboutPanel:]). Naturally this is all hooked up automagically.

It works great except for one thing: unlike most About windows, it shows up underneath all other windows, rather than on top. I believe this is because the application does not have a UI, so all its windows are automatically beneath other windows. Is there a way I can hook into the NSApplication mechanism for displaying the About window so I can send it to the front, and make it respond to ⌘-W so it can be closed from the keyboard? I've poked around in the docs for NSApplication, but there's no way to get a reference to the About window that I can see so that I can make it appear on top.

like image 534
mipadi Avatar asked Apr 24 '10 23:04

mipadi


1 Answers

Is there a way I can hook into the NSApplication mechanism for displaying the About window so I can send it to the front?

That's what orderFrontStandardAboutPanel: does.

It works great except for one thing: unlike most About windows, it shows up underneath all other windows, rather than on top. I believe this is because the application does not have a UI, so all its windows are automatically beneath other [applications'] windows.

Try bringing your application to the front with [NSApp activateIgnoringOtherApps:YES].

Note that how you make your application “not have a UI” matters: If you're using LSUIElement, that will work, whereas LSBackgroundOnly pretty strictly means background-only.

like image 79
Peter Hosey Avatar answered Sep 27 '22 02:09

Peter Hosey