svn
svn

Reputation: 142

How can I activate a specific window of an external application in OSX?

I'm trying to control Safari windows from my application.

I use this code to get the window list from Safari via ScriptingBridge:

SafariApplication *saf = [SBApplication ApplicationWithProcessIdentifier:myPid];
SBElementArray *safariWindows = [saf windows];

This works fine so far. I also can manage the order of the windows with the index property something like this:

SafariWindow *firstSafWin = [saf.windows objectAtIndex:0];
[firstSafWin setIndex: 1];
Now I try to activate Safari with:

NSRunningApplication *runApp =  [NSRunningApplication runningApplicationWithProcessIdentifier: myPid];           
    [runApp activateWithOptions: NSApplicationActivateAllWindows];

So here comes my problem:
Safari gets activated and the window I wanted is on top now, but it doesn't get the focus (or "mainWindow"). So the focus of the user input is still on the safari window which had the focus before I tried to change the order of the Safari windows.

Is there a way in OSX to get the focus to the Safari window I want?

Upvotes: 3

Views: 912

Answers (2)

LaC
LaC

Reputation: 12824

FWIW, what you are doing should work. You should file a bug report against Safari.

Upvotes: 0

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

The Accessibility API can give you this level of control but it must be enabled on the user's machine.

Upvotes: 1

Related Questions