views:

138

answers:

1

Hi,

I am writing an application that initially starts with just an NSStatusItem element. From its menu, the user can click a menu item that opens an NSWindow.

I would like that when that window is in focus, the application menu will be displayed. Is it possible?

+3  A: 

No, in order to get your application menu, you would have to transition the application into a foreground process (i.e., no longer an LSUIElement). Once you transition the application into the foreground, it can no longer transition back.

The function to transition the application to the foreground is TransformProcessType found in the Carbon Process Manager.

Your options here are 1) after bringing the process to the foreground with TransformProcessType, code up a clever little trick that closes and re-launches the application. Your other option 2) is to create a two-stage application (this is the option I would probably favor, if it's possible in your case) where part of the application is always in the background (i.e., LSUIElement). When that application wants to bring forward a window with a menu, it launches a helper application that contains the window, etc. as a regular application. When the user is done, that application is dismissed and closed out. The two applications could easily communicate through any number of IPC mechanisms, including UD sockets, Cocoa Distributed Objects, NSMessagePorts, etc.

Jason Coco