【问题标题】:Access second, third, ... drawer of a window via AppleScript通过 AppleScript 访问窗口的第二个、第三个...抽屉
【发布时间】:2011-07-31 19:27:32
【问题描述】:

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

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.(有时似乎不同,-1719 也有)。如果我不能写 first1 我不能写 second2 (产生相同的错误)。但是,我确信有办法,因为我可以访问第一个抽屉。有什么想法吗?

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

【问题讨论】:

    标签: applescript drawer


    【解决方案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
    

    【讨论】:

    • 抱歉,直到现在我都没有时间测试和验证解决方案。效果很好,正是我想要的。也感谢您的解释,从某处复制代码并在只有一个抽屉的应用程序上对其进行测试,但在双重嵌套列表中看不到重点。 :) 现在一切都清楚了,我渴望使用这些知识。非常感谢!
    猜你喜欢
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多