使另一个应用程序的窗口位于最前面并获得焦点
我一直在尝试从另一个应用程序获取任何给定的窗口,使其成为最前面和最集中的窗口。
以下是我尝试过的两种方法:
AppleScript
tell application "Safari"
set index of window "Downloads" to 1
activate
end tell
为什么不起作用: 虽然它似乎改变了 z 顺序,但它并没有改变焦点!前一个最前面的窗口即使被混淆,也会保留焦点。
CoreGraphicServices
CGSWindowOrder(cid, wid, kCGSOrderAbove, nil)
为什么不起作用:如果不是通用所有者,您就无法更改另一个进程拥有的窗口的顺序。在这种情况下,让自己成为通用所有者并不是一个选择——我不想废弃 Dock。
回顾
我需要在最前面创建一个窗口,并将其从一个进程聚焦到另一个进程。 AppleScript 无法聚焦,并且 CGS 不是一个选项,因为我不拥有该窗口。
有什么解决方案/想法吗?
I've been trying to get any given window from another Application to become 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 Accessibility API 将 AXPress 操作发送到 AXWindow。显然,用户需要打开辅助设备的访问权限。
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.