【问题标题】:How to access the text of a particular row of an outline control with AppleScript?如何使用 AppleScript 访问大纲控件特定行的文本?
【发布时间】:2013-05-25 10:10:27
【问题描述】:

我正在尝试使用 AppleScript 根据其文本选择大纲的特定行。

这是我正在考虑的(但不起作用):

repeat with aRow in rows of outline 1 of scroll area 1 of splitter group 1 of window 1
    set t to text of cell of aRow
    if t starts with "some text" then select aRow
end repeat

问题是text of cell of aRow 没有解决我认为应该的问题。 我已经使用 Accessibility Inspector 来确认对象层次结构。我尝试在行上使用“UI 元素”来查看哪些元素是可访问的,但它没有返回任何有用的东西。所以我没主意!我错过了什么?

【问题讨论】:

  • 呃...什么应用...
  • 我正在开发的一个。我正在使用 AppleScript 进行自动化 UI 测试。我是 AppleScript 的新手,为什么会有相关性?
  • 因为如果我们可以自己尝试访问大纲会有所帮助。并非所有应用程序都可以让您访问您所期望的信息。作为您的开发人员 afaik,您应该能够命名对象并自己输入任何相关信息。但我自己还没有尝试过。
  • 顺便说一句,如果你正在开发它。最好让它可编写脚本,而不是让用户在 GUI 上胡闹。看看developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/…developer.apple.com/library/mac/#technotes/tn2002/tn2106.html

标签: applescript nsoutlineview


【解决方案1】:

在@markhunte 的提示下,我想出了如何使用UI Elementsget properties 到达大纲中一行的文本。事实证明,辅助功能检查器显示的 AXRow > AXCell > AXStaticTexthierarchy 具有误导性。

每个文字都通过name of first UI Element of row (of outline...)访问。

这是我想要实现的工作代码:

tell application "System Events"
    tell process "MyApp"

        repeat with aRow in row of outline 1 of scroll area 1 of splitter group 1 of window 1
            if name of first UI element of aRow starts with "Schedule" then select aRow
        end repeat

    end tel
end tell

【讨论】:

    【解决方案2】:

    我认为您缺少的是静态文本

    这是一个使用 iTunes 的示例。

        tell application "System Events"
            tell process "iTunes"
    
                --  get properties of every static text in rows of outline 1 of scroll area 1 of splitter group 1 of window 1
    
                get properties of first static text in rows of outline 1 of scroll area 1 of splitter group 1 of window 1 whose description is "sources"
                get properties of first static text in rows of outline 1 of scroll area 1 of splitter group 1 of window 1 whose name is "LIBRARY"
                get properties of first static text in rows of outline 1 of scroll area 1 of splitter group 1 of window 1 whose value is "Spanish"
    
    
            end tell
        end tell
    

    【讨论】:

    • 谢谢马克,你通过向我展示获取属性的东西让我走上了正确的轨道。实际答案略有不同,因为我被无障碍检查员误导了。我的答案中有更多详细信息。再次感谢!
    • 很高兴它有帮助。自从我玩 GUI 脚本以来已经很长时间忘记了大部分内容。不是我的最爱。
    猜你喜欢
    • 1970-01-01
    • 2021-08-20
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多