5

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.

mipadi
  • 398,885
  • 90
  • 523
  • 479

1 Answers1

6

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • 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 Apr 25 '10 at 00:51
  • 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 Apr 25 '10 at 00:53
  • 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 Apr 25 '10 at 01:02
  • Oh, and to respond to your other point, I am using LSUIElement to hide the UI, not LSBackgroundOnly. – mipadi Apr 25 '10 at 01:03
  • Another piece of info: the About window *will* close when the Esc key is pressed. – mipadi Apr 25 '10 at 05:40