在 AppleScript 中选择弹出菜单按钮 [英] Selecting Pop Up Menu Buttons in AppleScript

查看:64
本文介绍了在 AppleScript 中选择弹出菜单按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动点击特定的弹出菜单项.例如,我想将消息接收声音"的值更改为其他值.我怎样才能用 AppleScript 做到这一点?以及如何使用 AppleScript 中的其他弹出菜单执行此操作?

I want to automate clicking a specific pop down menu's item. For Example, I want to change the Value of "Message receive Sound" to something else. How can I do this with AppleScript? And how can I do this with other pop down menus in AppleScript?

(要打开 iMessage 设置菜单,如图所示,打开 iMessage 后,键入 CMD COMMA)

(To open the iMessage Settings menu, shown in the image, type CMD COMMA, once you open iMessage)

注意:我已经成功地完成了这个 Automator,我只是想在 applescript 中做到这一点.

Note: I have successfully done this Automator, I just want to do it in applescript.

推荐答案

这称为 GUI 脚本.您必须确定对 UI 元素的引用.

It's called GUI scripting. You have to identify the reference to the UI element(s).

GUI 脚本强烈依赖于系统版本.如果更新更改了 UI 结构,脚本将停止运行.

GUI scripting strongly depends on the system version. If an update changes the UI structure the script will brake.

这会在声音弹出菜单中选择声音爆米花".是给 El Capitan 的.在系统中10.11 UI元素可能不同,进程名称可能是iChat"

This selects the sound "Popcorn" in the sound popup menu. It's for El Capitan. In systems < 10.11 the UI elements may be different and the process name might be "iChat"

tell application "System Events"
    tell process "Messages"
        set frontmost to true
        if not (exists (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")) then
            keystroke "," using command down
            repeat until exists (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")
                delay 0.1
            end repeat
        end if
        tell (1st window whose value of attribute "AXIdentifier" is "MessagesPreferencesWindow")
            tell pop up button 4 of group 1
                click
                delay 0.2
                click menu item "Popcorn" of menu 1
            end tell
        end tell
    end tell
end tell

这篇关于在 AppleScript 中选择弹出菜单按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆