gpt4 book ai didi

swift - 如何获取具有键盘/鼠标焦点的 Mac OS X 应用程序的显示范围?

转载 作者:行者123 更新时间:2023-11-30 11:12:43 25 4
gpt4 key购买 nike

我正在使用以下脚本来“最大化”我的 Mac 上的当前应用程序窗口。

当最前面的应用程序窗口位于主/较大的外部显示器上,或者当我的笔记本电脑未连接到外部显示器时,它可以正常工作。

但是,当我连接到外部显示器,并且我尝试最大化的窗口位于笔记本电脑显示器(而不是外部主显示器)上时,此脚本最终会将窗口放大到较大显示器的尺寸.

try
tell application "Finder" to set b to bounds of window of desktop
try
tell application (path to frontmost application as text)
set bounds of window 1 to {item 1 of b, 22, item 3 of b, item 4 of b}
end tell
on error
tell application "System Events" to tell window 1 of (process 1 where it is frontmost)
try
set position to {0, 22}
set size to {item 3 of b, (item 4 of b) - 22}
on error
click (button 1 of window 1 where subrole is "AXZoomButton")
end try
end tell
end try
end try

我相信问题在于我获得所需的边界b:

桌面窗口边界

这似乎总是返回主显示的边界。

我需要一种方法来检测当前正在运行的键盘和鼠标处于焦点的应用程序的显示范围。

注意:如果这个问题的解决方案是用 Swift 而不是 Apple Script,我就非常酷了。

最佳答案

您是否考虑过这一点:

tell application (path to frontmost application as text)
set zoomed of window 1 to true
end tell

关于swift - 如何获取具有键盘/鼠标焦点的 Mac OS X 应用程序的显示范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52022055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com