Bring app to foreground in 10.5

  • Hi,

    For apps that run in the background (LSUIElement=1,
    LSBackgroundOnly=1), the following code brings the app to the
    foreground under 10.4:

    // Transform process from background to foreground
    ProcessSerialNumber psn = { 0, kCurrentProcess };

    OSStatus returnCode = TransformProcessType(& psn,
    kProcessTransformToForegroundApplication);

    if( returnCode != 0)
    NSLog(@"Could not bring app to front. Error %d", returnCode);

    // Bring the main window back up
    [NSApp activateIgnoringOtherApps:YES];
    [mainWindow makeKeyAndOrderFront: self];

    In 10.5, however, this code no longer works 100%. The app window does
    come to the foreground, but not its menu bar. To make the app menu
    bar show up, one has to take the additional step of switching to some
    other app and then switching back.

    Does anyone know what needs to be done to bring the app menu bar back
    to foreground with the app?

    Thanks,

    -et
  • Did you file a bug?
    This sounds like something Apple would want to fix.
    Leopard changed a lot of stuff and there seem to be a fair number of
    edge cases that didn't get tested.

    On Nov 14, 2007, at 9:44 AM, Edison Thomaz wrote:

    > Hi,
    >
    > For apps that run in the background (LSUIElement=1,
    > LSBackgroundOnly=1), the following code brings the app to the
    > foreground under 10.4:
    >
    > // Transform process from background to foreground
    > ProcessSerialNumber psn = { 0, kCurrentProcess };
    >
    > OSStatus returnCode = TransformProcessType(& psn,
    > kProcessTransformToForegroundApplication);
    >
    > if( returnCode != 0)
    > NSLog(@"Could not bring app to front. Error %d", returnCode);
    >
    > // Bring the main window back up
    > [NSApp activateIgnoringOtherApps:YES];
    > [mainWindow makeKeyAndOrderFront: self];
    >
    > In 10.5, however, this code no longer works 100%. The app window
    > does come to the foreground, but not its menu bar. To make the app
    > menu bar show up, one has to take the additional step of switching
    > to some other app and then switching back.
    >
    > Does anyone know what needs to be done to bring the app menu bar
    > back to foreground with the app?
    >
    > Thanks,
    >
    > -et
  • You can also try SetFrontProcess(&psn). It may works better.

    Le 14 nov. 07 à 18:44, Edison Thomaz a écrit :

    > Hi,
    >
    > For apps that run in the background (LSUIElement=1,
    > LSBackgroundOnly=1), the following code brings the app to the
    > foreground under 10.4:
    >
    > // Transform process from background to foreground
    > ProcessSerialNumber psn = { 0, kCurrentProcess };
    >
    > OSStatus returnCode = TransformProcessType(& psn,
    > kProcessTransformToForegroundApplication);
    >
    > if( returnCode != 0)
    > NSLog(@"Could not bring app to front. Error %d", returnCode);
    >
    > // Bring the main window back up
    > [NSApp activateIgnoringOtherApps:YES];
    > [mainWindow makeKeyAndOrderFront: self];
    >
    > In 10.5, however, this code no longer works 100%. The app window
    > does come to the foreground, but not its menu bar. To make the app
    > menu bar show up, one has to take the additional step of switching
    > to some other app and then switching back.
    >
    > Does anyone know what needs to be done to bring the app menu bar
    > back to foreground with the app?
    >
    > Thanks,
    >
    > -et
  • Good idea! Just filed a bug. For those interested, the bug id is
    5599887.

    -et

    On Nov 14, 2007, at 12:47 PM, John Stiles wrote:

    > Did you file a bug?
    > This sounds like something Apple would want to fix.
    > Leopard changed a lot of stuff and there seem to be a fair number
    > of edge cases that didn't get tested.
    >
    >
    > On Nov 14, 2007, at 9:44 AM, Edison Thomaz wrote:
    >
    >> Hi,
    >>
    >> For apps that run in the background (LSUIElement=1,
    >> LSBackgroundOnly=1), the following code brings the app to the
    >> foreground under 10.4:
    >>
    >> // Transform process from background to foreground
    >> ProcessSerialNumber psn = { 0, kCurrentProcess };
    >>
    >> OSStatus returnCode = TransformProcessType(& psn,
    >> kProcessTransformToForegroundApplication);
    >>
    >> if( returnCode != 0)
    >> NSLog(@"Could not bring app to front. Error %d", returnCode);
    >>
    >> // Bring the main window back up
    >> [NSApp activateIgnoringOtherApps:YES];
    >> [mainWindow makeKeyAndOrderFront: self];
    >>
    >> In 10.5, however, this code no longer works 100%. The app window
    >> does come to the foreground, but not its menu bar. To make the app
    >> menu bar show up, one has to take the additional step of switching
    >> to some other app and then switching back.
    >>
    >> Does anyone know what needs to be done to bring the app menu bar
    >> back to foreground with the app?
    >>
    >> Thanks,
    >>
    >> -et
previous month november 2007 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    
Go to today