user-interface - 在 AppleScript 中选择弹出菜单按钮

标签 user-interface applescript imessage

我想自动单击特定的弹出菜单项。 例如,我想将“消息接收声音”的值更改为其他值。我怎样才能用 AppleScript 做到这一点?我怎样才能用 AppleScript 中的其他弹出菜单来做到这一点?

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

注意:我已经成功完成了这个Automator,我只想在applescript中完成它。

enter image description here

最佳答案

这称为 GUI 脚本。您必须识别对 UI 元素的引用。

GUI 脚本很大程度上取决于系统版本。如果更新更改了 UI 结构,则脚本将会中断。

这会在声音弹出菜单中选择声音“Popcorn”。这是为了埃尔卡皮坦。在 10.11 之前的系统中,UI 元素可能不同,进程名称可能是“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

关于user-interface - 在 AppleScript 中选择弹出菜单按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36549556/

相关文章:

java - float 按钮是AWT?

bash - 使用脚本操作 OS X 窗口

objective-c - 为什么 AppleScript "tell"命令在后台运行 GUI 应用程序的非 GUI 实例?

macos - 点击苹果通知重定向到applescript编辑器

swift - InsertAttachment withAlternateFilename 在 iOS 10 中不起作用

java - GUI (java) 中的 jTable 不显示数据库中的所有数据!表模型中的错误?

java - 我的标签未显示在 GUI 前缀表达式程序中

ios - 验证 iMessage 支持、SMS 支持

ios - 识别来电 - iOS

java - java中显示和隐藏框架的正确方法