从窗口菜单中获取按钮列表 - AppleScript

时间:2012-07-07 02:48:15

标签: button menu applescript itunes automator

我可以获得一个主菜单项,并且我已经能够使用系统事件来选择并单击窗口中的特定按钮。我遇到了一个问题,我想获得属于弹出“工作表”的按钮的“句柄”。例如,iTunes中的“airplay”按钮:

In this case there are 2 items

我可以点击按钮打开表格,使用类似的内容:

click button 10 of window "iTunes" of application process "iTunes" of application "System Events"

我可以使用key code手动上下滚动,但我正在寻找一种选择我想要的特定按钮的最有效和优雅的解决方案(通过名称,在这种情况下为“计算机”)< / p>

我正在使用辅助功能检查器,我可以获得有关菜单的一些信息:

<AXApplication: “iTunes”>
 <AXWindow: “iTunes”>
  <AXMenu>
   <AXMenuItem: “AirPort Express”>

Attributes:
   AXRole:  “AXMenuItem”
   AXRoleDescription:  “menu item”
   AXParent:  “<AXMenu>”
   AXEnabled:  “1”
   AXPosition:  “x=1070 y=798”
   AXSize:  “w=146 h=22”
   AXTitle:  “AirPort Express”
   AXHelp:  “(null)”
   AXSelected (W):  “1”
   AXMenuItemCmdChar:  “(null)”
   AXMenuItemCmdVirtualKey:  “(null)”
   AXMenuItemCmdGlyph:  “(null)”
   AXMenuItemCmdModifiers:  “0”
   AXMenuItemMarkChar:  “(null)”
   AXMenuItemPrimaryUIElement:  “(null)”

Actions:
   AXCancel - cancel
   AXPress - press

这些弹出窗口是否有特定的标题?与select button 1 of sheet 1 of...

一样

我认为这很容易,我在考虑这个问题。

喝彩! 博

我做了什么:

    --click menu item "Computer" of menu 1 of window "iTunes" of application process "iTunes"
    --tell application "System Events" to tell process "iTunes"
    --  tell menu 1 of menu bar item 1 of menu bar 2
    --      click menu item "Copy"
    --  end tell
    --end tell
    --click (every button whose value of attribute "AXTitle" is "Computer") of window "iTunes" of application process "iTunes"
    --tell window 1
    --click button "Computer" of tool bar 1 of window "iTunes" of application process "iTunes"
    --  click button 1 of group 1 of group 1 of window "iTunes" of application process "iTunes"
    --end tell
    click (menu item 2 of every menu item whose attribute "AXRoleDescription" is "menu item") of window "iTunes" of application process "iTunes"
    --click (button whose description is "menu item") of window "iTunes" of application process "iTunes"

2 个答案:

答案 0 :(得分:1)

在自定义菜单上无法实现:<Window "iTunes"> --> <Menu>

可以在弹出按钮上显示。 <Window "iTunes"> --> <popup button> --> <Menu>

您必须继续使用key code

答案 1 :(得分:0)

辅助功能检查器中显示的层次结构是您需要使用的层次结构。菜单在弹出之前是不可用的,所以你可能需要稍等一下 - 我没有任何外部扬声器可以测试,但你会做类似的事情:

tell application "System Events"
    click button 10 of window "iTunes" of application process "iTunes"
    delay 1 -- give menu time to pop up
    click menu item "Computer" of menu 1 of window "iTunes" of application process "iTunes"
end tell

弹出菜单后,您也可以使用click menu item "Computer" of front menu。如果索引不正确,您通常可以通过弹出菜单来回溯层次结构,然后获取菜单以找到正确的索引,然后获取菜单的菜单项等。