【问题标题】:Using AppleScript to click the plus (+) button in a preferences window使用 AppleScript 单击首选项窗口中的加号 (+) 按钮
【发布时间】:2011-10-25 22:31:52
【问题描述】:

使用 AppleScript 我想在多台机器上自动创建新用户帐户。我正在尝试使用 UI 脚本,但似乎无法在 iChat 帐户首选项窗口中的“添加帐户”(+) 按钮上执行单击命令。我尝试使用 Accessibility Inspector.app 来推断按钮的名称,但我似乎仍然无法通过 AppleScript 访问它。

根据 Accessibility Inspector.app,该按钮具有以下属性:

AXRole: AXButton
AXRoleDescription: button
AXHelp: <nil>
AXEnabled: YES
AXFocused (W): NO
AXParent: <AXGroup>
AXWindow: <AXWindow:AXStandardWindow>
AXTopLevelUIElement: <AXWindow:AXStandardWindow>
AXPosition: x=225.00 y=462.00
AXSize: w=23.00 h=22.00
AXTitle: <empty string>
AXIdentifier: _NS:27
AXDescription: Add Account

这是一个示例启动 AppleScript,可让您进入 Accounts Preference 窗口:

tell application "iChat"
    activate
    tell application "System Events"
        tell process "iChat"
            tell menu bar 1
                click menu item "Preferences…" of menu "iChat"
            end tell
            click button "Accounts" of tool bar 1 of window 1
            click button "Add Account" of window "Accounts"
        end tell
    end tell
end tell

请注意,第 9 行是我正在尝试的工作。您将在下面找到指向 iChat 帐户首选项窗口屏幕截图的链接,其中箭头指向我尝试访问的按钮。另请注意,我知道我可以使用“按键选项卡”来访问(+)按钮,但这并不总是有效,因为您必须按下选项卡的次数会根据您已经创建的帐户类型而变化iChat。

iChat Account Preferences Window

【问题讨论】:

    标签: applescript


    【解决方案1】:

    并非每个 Ui 对象都有标题,因此在这些情况下,您可以只使用项目编号 - 请注意,您需要包含 Inspector 窗口中显示的整个层次结构。

    tell application "iChat"
        activate
        tell application "System Events"
            tell process "iChat"
                tell menu bar 1 to click menu item "Preferences…" of menu "iChat"
                delay 0.5
                tell window 1
                    click button "Accounts" of tool bar 1
                    delay 0.5
                    click button 1 of group 1 of group 1
                end tell
            end tell
        end tell
    end tell
    

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多