开发者

Access second, third, ... drawer of a window via AppleScript

I want to 开发者_开发知识库measure the size and position of a window including its drawers. I already found out how to get the size / position of the first drawer, but I can't find a way (neither Google neither trying) to access other drawers. You can access the first drawer doing something like the following:

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

If I write first drawer or drawer 1 I get the error Execution Error: Can’t get item 1 of 116. (last number varies) and Error -1728. (seems to vary sometimes, had -1719 as well). If I cannot write first or 1 I can't write second or 2 (yield the same error). However, I'm sure there is a way since I can access the first drawer. Any ideas?

PS: For testing purposes I created a simple App which only contains a window with 4 buttons to trigger a drawer per edge. I pushed it to github, therefore you can clone it and play around by yourself if you like.


Since there are multiple properties for a drawer, when you get the size of the drawer you are getting a list of the specified properties of the drawers (e.g. {{465, 117}} for one drawer). You can get an individual size by getting an item of that list (e.g. the first size, which is also a list, would be {465, 117}), but you could also just go through the current drawers, whatever they are.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜