【问题标题】:Choosing combo box item with AppleScript doesn't trigger item action使用 AppleScript 选择组合框项目不会触发项目操作
【发布时间】:2013-02-22 22:14:17
【问题描述】:

我正在尝试使用 AppleScript 单击选择框中的项目。

当使用鼠标手动单击“更多...”项目时,会打开一个标准的 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

...现在我没有主意了。

【问题讨论】:

    标签: applescript


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

    【讨论】:

      【解决方案2】:

      在这里你可以找到有类似问题的人,答案也是cliclick

      https://discussions.apple.com/message/17662850#17662850

      【讨论】:

      • 虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。
      猜你喜欢
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      • 2014-10-09
      • 1970-01-01
      相关资源
      最近更新 更多