访问第二、第三。。。通过AppleScript的窗口抽屉

访问第二、第三。。。通过AppleScript的窗口抽屉,applescript,drawer,Applescript,Drawer,我想测量窗户的大小和位置,包括抽屉。我已经找到了如何获取第一个抽屉的大小/位置,但我找不到一种方法(谷歌也不尝试)访问其他抽屉。您可以通过以下操作访问第一个抽屉: 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

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

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
如果我写
第一个抽屉
第一个抽屉
,我会得到错误
执行错误:无法得到116中的第1项。
(最后一个数字不同)和
错误-1728。
(有时似乎有所不同,也有
-1719
)。如果我不能先写
1
,我就不能再写
2
(产生相同的错误)。不过,我肯定有办法,因为我可以进入第一个抽屉。有什么想法吗


PS:出于测试目的,我创建了一个简单的应用程序,它只包含一个窗口,每个窗口有4个按钮,可以触发每个边缘的抽屉,因此,如果您愿意,您可以克隆它并自己玩。

因为一个抽屉有多个属性,当您获得抽屉的大小时,您将获得一个抽屉指定属性的列表(例如,一个抽屉的{465117})。您可以通过获取该列表中的一项来获取单个大小(例如,第一个大小也是列表,将为{465117}),但您也可以只查看当前抽屉,不管它们是什么

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

很抱歉,到目前为止,我没有时间测试和验证解决方案。非常好,这正是我想要的。同样感谢您的解释,从某处复制了代码,并在只有一个抽屉的应用程序上进行了测试,但没有看到双嵌套列表中的要点。:)现在一切对我来说都很清楚,我渴望运用这些知识。谢谢!