通过AppleScript访问窗口的第二个,第三个,...抽屉

时间:2011-07-31 19:27:32

标签: 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 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 drawerdrawer 1,我会收到错误Execution Error: Can’t get item 1 of 116.(最后一个号码不同)和Error -1728.(有时似乎有所不同,-1719first好)。如果我无法写1second我无法写2或{{1}}(产生相同的错误)。但是,我确信有一种方法,因为我可以访问第一个抽屉。有什么想法吗?

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

1 个答案:

答案 0 :(得分:1)

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

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