0

我想测量一个窗口的大小和位置,包括它的抽屉。我已经找到了如何获取第一个抽屉的大小/位置,但我找不到访问其他抽屉的方法(谷歌也没有尝试)。您可以通过以下方式访问第一个抽屉:

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 上,所以你可以克隆它并自己玩。

4

1 回答 1

1

由于抽屉有多个属性,因此当您获取抽屉的大小时,您将获得抽屉指定属性的列表(例如,一个抽屉的 {{465, 117}})。您可以通过获取该列表中的一个项目来获得单独的尺寸(例如,第一个尺寸,也是一个列表,将是 {465, 117}),但您也可以只浏览当前的抽屉,无论它们是什么。

repeat with aDrawer in (drawers of appWindow)
    set {w, h} to size of aDrawer
    set {x, y} to position of aDrawer
    -- add to overall window size if larger, etc
end repeat
于 2011-07-31T21:31:58.427 回答