TransformProcessType fails to show menu bar
I wasn't sure if this should go to carbon-dev or cocoa-dev, but
ultimately since this is a pretty low-level API and I suspect my
problem interacts with Cocoa, I figured cocoa-dev would do.
I have an application which I would like to function in both
"background" and "foreground" mode. Basically, when launched from
login items (or when relaunching itself) it will be in background
mode, presenting little UI and watching user actions to display helper
windows when appropriate. When explicitly double-clicked from the
Finder, it will pop up a Dock icon and a menu bar and such and act
like a normal application so the user can set preferences and the
I know that the "standard" way to do this is to have two apps. I'd
really like to avoid this if I can. I've done it before, and it was
less than fun. Seems like having a single app that switches modes
ought to work, in any case.
So, the actual problem: I set LSUIElement to 1 in my Info.plist and
use TransformProcessType to bump to a foreground application. This
works except that it fails to show my app's menu bar. Switching to
another program and back to mine makes it show correctly.
I've tried using LSBackgroundOnly, SetFrontProcess, [NSApp
activateIgnoringOtherApps:YES], and none of them change things. I even
tried to manually perform the switch to another app, by doing
GetFrontProcess beforehand, then setting it front and then my own. No
I finally stumbled upon a partial workaround. If I do
TransformProcessType/SetFrontProcess in main() before the call to
NSApplicationMain(), it works as expected. But only if I launch from
Finder, not Xcode. The behavior when launched from Finder is just what
I want so I'm somewhat happy, but the continuing broken behavior in
Xcode makes me worry.
Apparently I'm not the only one to hit this problem:
Alas, no solutions there.
So, does anyone know what's going on, or a better workaround than the
partial one I've managed to find?
On Thu, May 1, 2008 at 12:52 AM, Michael Ash <michael.ash...> wrote:
> So, the actual problem: I set LSUIElement to 1 in my Info.plist and
> use TransformProcessType to bump to a foreground application. This
> works except that it fails to show my app's menu bar. Switching to
> another program and back to mine makes it show correctly.
In the absence of any replies I've gone ahead and filed a bug about
this problem. rdar://5905139 If any Apple employees feel like giving
it some love, your efforts will not go unappreciated.