views:

47

answers:

1

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.

+1  A: 

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.

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.

Peter Hosey
Thanks. Is there a way that I can also make the window respond to the ⌘-W keyboard event, so it can be closed from the keyboard? The window comes to the front now, but pressing ⌘-W does not close it (instead, I just get the system alert sound for when a keyboard shortcut is invalid).
mipadi
Do you have a main menu? Even if it ordinarily won't be visible, you should still have a main menu to handle keyboard shortcuts like ⌘W, ⌘Z, ⌘C, ⌘V, etc.
Peter Hosey
I didn't have one, but I added one. It has the usual "Close" item with the proper keyboard shortcut, but it's still not working.
mipadi
Oh, and to respond to your other point, I am using LSUIElement to hide the UI, not LSBackgroundOnly.
mipadi
Another piece of info: the About window *will* close when the Esc key is pressed.
mipadi