Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cowgp

macrumors newbie
Original poster
Sep 19, 2005
6
0
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?

thanks
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Use Applescript:

Code:
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".
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

cowgp

macrumors newbie
Original poster
Sep 19, 2005
6
0
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.