开发者

Making a another applications's window frontmost and focused

I've been trying to get any given window from another Application to 开发者_如何学JAVAbecome front most and focused.

Here are the two methods I have tried:

AppleScript

tell application "Safari"
   set index of window "Downloads" to 1
   activate
end tell

Why it doesn't work: While it seems to change the z-Order, it doesn't change the focus! The previous frontmost window, even if obfuscated, retains focus.

CoreGraphicServices

CGSWindowOrder(cid, wid, kCGSOrderAbove, nil)

Why it doesn't work: Without being the Universal Owner, you can't change the order of a window owned by another process. In this case, making myself the Universal Owner is not an option -- I don't want to depose the Dock.

Recap

I need to make a window frontmost and focused from one process to another. AppleScript fails to focus, and CGS isn't an option since I don't own the window.

Any solutions/ideas?


Try using the Accessibility API to send an AXPress action to the AXWindow. Obviously, the user will need to have access for assistive devices turned on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜