I've got an application that runs at startup as a menu in the OS X menu bar (i.e., as a background application). When you select an option from the menu, it transforms into a foreground application (creating a dock icon) and shows a window.
Here's the background/foreground code I'm using:
+(void) TransformToForegroundApplication {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
+(void) TransformToBackgroundApplication {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}
Pretty standard stuff, from the looks of things. And it works fine, except for one small issue.
The problem is that after I call TransformToForegroundApplication, I call makeKeyAndOrderFront: on the window to make it come to the front of the Z-order and receive focus - but it does neither. It shows up in the background, underneath everything else. I need to either click on the dock icon, or minimize all of the windows in front of it and then click on that window, in order to bring it to the front.
Any ideas?