The following code works for me on 10.6.7. Leaving out any of the calls after 
TransformProcessType result in the problem you describe.

      ProcessSerialNumber psn;
      pid_t pid = getpid();
      OSStatus err;
      err = GetProcessForPID(pid, &psn);
      err = TransformProcessType(&psn, 
kProcessTransformToForegroundApplication);
      err = ShowHideProcess(&psn, true);
      [NSMenu setMenuBarVisible:NO];
      SetFrontProcess(&psn);
      [NSMenu setMenuBarVisible:YES];

/Anders

On 2011-05-25, at 19:08 , Jerry Krinock wrote:

> I spent a couple hours last night re-disovering Apple Bug ID #5905139 which 
> was supposedly opened three years ago by Mike Ash [1].  Mike said:
> 
> "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."
> 
> He also said that he was doing the switch when the app launched.  Actually, 
> that works OK for me, so maybe that bug has been fixed as of 10.6.7.  
> However, I have a more challenging requirement.  My app launches as 
> LSUIBackgroundOnly and can show a Status Item (aka menulet).  My Status Item 
> includes a "Show Menu" menu item.  This item targets TransformProcessType().  
> So you see the transformation may occur hours after launch.  It is only after 
> this delayed transform that I see the problem; the user needs to activate 1-2 
> other apps and return to mine before my menu shows.  As Mike found, it's 
> worse if the app was spawned by Xcode/gdb.
> 
> So I tried all kinds of things last night: -activateIgnoringOtherApps:YES of 
> course, iterating through all of the -[NSApp windows] and sending them each 
> of them a -display, -makeKeyAndOrderFront:YES.  Nada.  I machine-gunned them 
> with loops and delays, and finally broke out NSAppleScript and tried 
> alternately activating my app and the currently active application.  Still no 
> good.
> 
> Since users will do this rarely or more likely never, I wouldn't mind 
> programatically cycling through their frontmost, 2nd-frontmost and 
> 3rd-frontmost apps if I knew what they were so I could restore them to their 
> prior order.  But even the shiny new -[NSWorkspace runningApplications] 
> documentation says that "the order of the array is unspecified".  (Arghh! 
> Why?)  System Events gives no more than the one active application either.
> 
> But that may not work anyhow.  Can anyone think of any other bricks I could 
> try throwing at this?
> 
> Thanks,
> 
> Jerry Krinock
> 
> [1] 
> http://www.cocoabuilder.com/archive/cocoa/205558-transformprocesstype-fails-to-show-menu-bar.html?q=TransformProcessType#205558_______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/ano%40bahnhof.se
> 
> This email sent to a...@bahnhof.se

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to