我想测量一个窗口的大小和位置,包括它的抽屉。我已经找到了如何获取第一个抽屉的大小/位置,但我找不到访问其他抽屉的方法(谷歌也没有尝试)。您可以通过以下方式访问第一个抽屉:
tell application "System Events"
set appProcess to the first process whose name is "DrawerTest"
set appWindow to the first window of appProcess
if (count drawers of appWindow) > 0 then
set {{w, h}} to size of drawer of appWindow
set {{x, y}} to position of drawer of appWindow
set drawerBounds to {x, y, x + w, y + h}
end if
end tell
drawerBounds
如果我写first drawer
或者drawer 1
我得到错误Execution Error: Can’t get item 1 of 116.
(最后一个数字不同)和Error -1728.
(有时似乎不同,也有-1719
)。如果我不能写first
或者1
我不能写second
或者2
(产生同样的错误)。但是,我确信有办法,因为我可以访问第一个抽屉。有任何想法吗?
PS:出于测试目的,我创建了一个简单的应用程序,它只包含一个带有 4 个按钮的窗口,以触发每个边缘的抽屉。我把它推到了 github 上,所以你可以克隆它并自己玩。