launchApplication is not activated as well?

Discussion in 'Mac Programming' started by cowgp, Apr 14, 2008.

  1. cowgp macrumors newbie

    Sep 19, 2005
    What should have been a rather simple task seems to not be...

    in my Cocoa app I reach a point where after doing a version check on iTunes, I launch it and need it to be brought to the foreground... in 10.4 simply doing this statement does this correctly.

    [[NSWorkspace sharedWorkspace] launchApplication:mad:"iTunes"];

    however in 10.5.2, the application requested (iTunes) is launched effectively at the bottom of the stack (if you immediately invoke app swither, iTunes is the last in the row).

    I cant seem to find any API call for activating or "focusing" another app other than your own... any ideas on what the API call would be?

  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Use Applescript:

    tell application "iTunes" to activate
    This will force the app to the "top" even switching spaces if required. You can call if via any of the standard methods (NSAppleScript for example).

    I would note that they API you used never promised to bring the app to the front/focus it, simply to launch it. Perhaps it used to work that way, but that was just "luck".
  3. kainjow Moderator emeritus


    Jun 15, 2000
    A more direct approach would be to use the Carbon function SetFrontProcess(). Go here for more info.

    Also you could use the NDProcess class to do this, which is just a wrapper around the Carbon process manager functions.
  4. cowgp thread starter macrumors newbie

    Sep 19, 2005
    Wonderfully simple help... thanks! it worked perfectly.

    You are correct, the launchApplication API never said it would focus the app, but I couldn't find any API for doing it and it was "doing" it... so...

    anyways. thanks again for the help and quick response.
  5. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Strangely, one of the options for the NSWorkspace method launchAppWithBundleIdentifier:eek:ptions:additionalEventParamDescriptor:launchIdentifier: is NSWorkspaceLaunchWithoutActivation, which will, according to the docs, "Launch the application but do not bring it into the foreground." Which to me would seem to imply that the default is for the application to be brought to the foreground (since there is no other option to explicitly bring the app to the front). Then again, maybe that method isn't calling launchApplication: directly and works differently, activating by default.

Share This Page