2

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

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

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

在此处输入图像描述

4

1 回答 1

3

它被称为 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
于 2016-04-11T13:42:33.617 回答