swift - 如何获得具有键盘/鼠标焦点的 Mac OS X 应用程序的显示范围?
问题描述
我正在使用以下脚本来“最大化”我 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
我相信问题是我得到想要的方式bounds
,b
:
bounds of window of desktop
这似乎总是返回主显示器的边界。
我需要一种方法来检测当前正在运行的应用程序的显示边界,该应用程序具有键盘和鼠标焦点。
注意:如果这个问题的解决方案是 Swift 而不是 Apple Script,我会非常酷。
解决方案
你有没有考虑过这个:
tell application (path to frontmost application as text)
set zoomed of window 1 to true
end tell
推荐阅读
- linux - Linux/Golang:无法访问 /sys/kernel/debug/tracing/kprobe_events
- python - 在数据帧上应用 lambda 函数时将数据帧作为参数传递
- kotlin - ArchUnit 不区分大小写的名称匹配
- c# - 计算未执行以计算 c#asp.net sql linq 中 2 个日期之间的总天数差异
- javascript - 使用 Apple REST API 登录时无法获取电子邮件地址或 Apple ID
- safari - Safari ITP 2.3:所有脚本可写网站数据的生命周期上限
- r - “`[[<-`(`*tmp*`, i, value = ) 中的错误:在级别 1 没有这样的索引”将 for 循环结果分配给列表
- python - 在 docker build 中运行 pip install requirements.txt 失败
- c# - 如何在 C#.net 中使用 YOLO 提高对象检测的速度
- python - 关键字参数后的位置参数和 * 参数后的常规参数