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];
SBElem开发者_运维问答entArray *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?
The Accessibility API can give you this level of control but it must be enabled on the user's machine.
FWIW, what you are doing should work. You should file a bug report against Safari.
精彩评论