2014-12-04 26 views
0

我想獲取UI的索引。我喜歡跟隨,但我不能。有什麼辦法嗎?如何獲取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 
+0

你的目標是什麼? – adayzdone 2014-12-04 13:14:19

+0

@adayzdone:「系統偏好設置」。但我認爲它不需要指定應用程序來回答我的問題。 – 2014-12-04 13:52:13

回答

2

的AS系統夏娃nts UI元素套件不包含像UI元素或索引這樣的屬性。致電

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則。

邁克爾/漢堡問候