如何获取UI索引?

时间:2014-12-04 11:44:45

标签: applescript

我想获得UI的索引。我确实喜欢跟随,但我不能。有什么办法吗?

源:

tell application "System Events"
    tell process "System Preferences"
        index of button 9 of scroll area 1 of window 1
    end tell
end tell

结果:

error

预期结果:

9

1 个答案:

答案 0 :(得分:2)

AS System Events UI Elements Suite不包含UI元素的id或索引等属性。电话

button 9 of scroll area 1 of window 1

只定位第九个按钮,而不是id 9按钮。你也可以写

ninth button of scroll area 1 of window 1

我能想到返回9的唯一方法就是通过重复循环遍历所有按钮:

tell application "System Preferences" to activate

tell application "System Events"
    tell process "System Preferences"
        repeat with ix from 1 to count (buttons of scroll area 1 of window 1)
            if name of button ix of scroll area 1 of window 1 = "Monitors" then
                return ix
            end if
        end repeat
    end tell
end tell

结果是9。

问候,迈克尔/汉堡