Re: Coding around a known bug - SOLVED (acceptably)
Re: Coding around a known bug - SOLVED (acceptably)
- Subject: Re: Coding around a known bug - SOLVED (acceptably)
- From: Steve Cronin <email@hidden>
- Date: Sat, 02 Aug 2008 23:39:40 -0500
Andrew & Aaron
Yes I have read the discussion in the docs related to
TransformProcessType(). My bad - here's a more complete snippet:
if (...some condition..) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSStatus returnCode = TransformProcessType(&psn,
kProcessTransformToForegroundApplication);
if( returnCode == 0) { SetFrontProcess(&psn); }
}
The result of this is that an icon does appear in the dock BUT the
menubar is NOT shown until the application toggling business I
described in the initial email occurs.
I've also tried all Aaron's various suggestions related to NSMenu, and
NSApplication all with the same result.
Seems to me TransformProcessType(&psn,
kProcessTransformToForegroundApplication) leaves the transformed
process in a strange state; a state not expected by NSApplication.
So here's what I've finally gotten to as an acceptable solution.
This flashes the menubar but otherwise the context switch is as
expected - no unexpected app jumps to front.
(AppleScriptTool is a custom object which has various convenience
methods I've developed)
NSString *currentApp = [AppleScriptTool stringFromAppleScript:@"tell
application \"System Events\" to name of first process whose frontmost
is true"];
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSStatus returnCode = TransformProcessType(&psn,
kProcessTransformToForegroundApplication);
if( returnCode == 0) {
[[NSWorkspace sharedWorkspace] launchApplication:currentApp]; //
this step is necessary - if left out the menubar is not updated
[AppleScriptTool
bringApplicationToFront:myAppName]; //uses @"tell
application \"%@\" to activate" [NOTE: SetFrontProcess() doesn't work]
}
I cannot use NSWorkspace's -activeApplication in the first line
because it sees the calling app as the active app...
It also seems to me that when (if) Apple does fix
TransformProcessType(), since the call to SetFrontProcess() is spelled
out as necessary, that my solution will not break nor result in
undesired behavior.
Maybe someone else will find this useful...
Thanks to all,
Steve
On Aug 2, 2008, at 6:11 PM, Andrew Merenbach wrote:
On Aug 2, 2008, at 9:40 AM, Steve Cronin wrote:
Folks:
I'm looking for some advice on how to code around a Leopard bug
(radar 5905139 & 5599887).
Leopard broke the following:
OSStatus returnCode = TransformProcessType(&psn,
kProcessTransformToForegroundApplication);
TransformProcessType used to bring a background app to the
foreground, which it still does EXCEPT for the fact that the
menubar does not get correctly established until the user first
brings another app to the foreground and then re-establishes the
'wounded' app as the foreground. Once this 'app toggling' is done,
all is well.
So I can trap Tiger v. Leopard and do toggling only on Leopard,
that's pretty straight-forward.
What I'm looking for is best advice on how to get the menubar to be
'right' in code.
I've tried:
[[NSWorkspace sharedWorkspace] launchApplication:@"Finder"];
followed by an Applescript to 'activate' myself.
OK it works, but it jarring to have the 'Finder' just suddenly jump
into view and I'm quite sure customers will NOT like it.
Any thoughts?
Also any thoughts on how possibly to code this so that when, or if,
Apple ever fixes TransformProcessType that the fix might right
itself and not require a new version.
Thanks,
Steve
Hi, Steve,
The docs appear to mention something that may be of use -- see the
Discussion for TransformProcessType():
You can use this call to transform a background-only application
into a foreground application. A foreground application appears in
the Dock (and in the Force Quit dialog) and contains a menu bar.
This function does not cause the application to be brought to the
front; you must call SetFrontProcess to do so.
Apologies if you are already, but -- are you calling
SetFrontProcess()?
Cheers,
Andrew
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden