2013-02-22 50 views
1

我試圖使用AppleScript單擊選擇框中的項目。使用AppleScript選擇組合框項目不會觸發項目動作

Screenshot of the window

與標準的OSX文件選擇對話框打開鼠標手動點擊「更多...」的商品,但是當我嘗試做使用AppleScript,「更多...」的商品其顯示爲選擇框的選定項目,但不顯示對話框。

到目前爲止,我已經試過......(元素名稱從Automator的記錄來)

tell application "System Events" 

    click static text 1 of window 1 of application process "DYMO Word Addin" 
    -- combo box arrow 
    click UI Element 1 of combo box 2 of group 1 of window 1 of application process "DYMO Word Addin" 

    set labelsList to (list 1 of scroll area 1 of combo box 2 of group 1 of window 1 of application process "DYMO Word Addin") 
    set numLabelsInList to (count text fields of labelsList) 
    set theTextField to (text field numLabelsInList of labelsList) 

    if numLabelsInList > 1 then 

      repeat with z from 1 to (numLabelsInList - 1) 
        key code 125 -- down arrow 
      end repeat 

    end if 

    -- stuff I've tried 

    click theTextField 
    keystroke return 
    key code 36 -- return 
    set focused of theTextField to true 
    set value of attribute "AXFocused" of theTextField to true 
    perform action "AXConfirm" of theTextField 

end tell 

...現在我的想法。

回答

1

經過一番測試之後,事實證明文件對話框只有在組合框具有焦點時纔會打開,並且單擊組合框箭頭按鈕和菜單項實際上並不會使焦點集中。

http://lists.apple.com/archives/accessibility-dev/2006/Oct/msg00013.html

嘗試所有的從該線程的方法來給元素焦點,即使在「點擊」沒有工作。

https://apple.stackexchange.com/questions/40141/when-mousekeys-are-on-how-do-i-click-or-move-the-mouse-using-applescript#answer-40859

這個答案建議cliclick的另一種方式來移動和點擊鼠標,它的工作。

所以最後我結束了

click static text 1 of window 1 of application process "DYMO Word Addin" 
set labelsComboBox to (combo box 2 of group 1 of window 1 of application process "DYMO Word Addin") 

tell labelsComboBox 
     set {xPosition, yPosition} to position of labelsComboBox 
     set {xSize, ySize} to size 
end tell 

set {realXPosition, realYPosition} to {(xPosition + (xSize div 2)) as string, (yPosition + (ySize div 2)) as string} 

do shell script "/usr/local/bin/cliclick m:" & realXPosition & "," & realYPosition & " dc:" & realXPosition & "," & realYPosition 

-- combo box arrow 
click UI element 1 of labelsComboBox 

...