Coding around a known bug

  • 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
  • On Aug 2, 2008, at 11: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.

    Why not just use the AppleScript to bring your app to the foreground
    in the first place, instead of TransformProcessType?

    Charles
  • Charles;

    Because I need to convert the app from a background (LSUIElement=1)
    application.
    I am not aware of an AppleScript way to do that.
    If there is one, can you share a pointer?

    Thanks for your time!
    Steve

    On Aug 2, 2008, at 1:40 PM, Charles Srstka wrote:

    > On Aug 2, 2008, at 11: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.
    >
    > Why not just use the AppleScript to bring your app to the foreground
    > in the first place, instead of TransformProcessType?
    >
    > Charles
  • On Aug 2, 2008, at 1:58 PM, Steve Cronin wrote:

    > Charles;
    >
    > Because I need to convert the app from a background (LSUIElement=1)
    > application.
    > I am not aware of an AppleScript way to do that.
    > If there is one, can you share a pointer?

    Ah, sorry, I misunderstood what you were trying to do.

    Charles
  • 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
  • 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
    >
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today