有没有办法使用 AppleScript 使 Google Chrome 中的选项卡静音?

Is there a way to mute a tab in Google Chrome using AppleScript?

所以我想制作一个小脚本,例如静音 URL 包含 google.com 的所有选项卡。我想做这样的事情:

tell application "Google Chrome"
    set theWindows to windows of application "Google Chrome"
    repeat with theWindow in theWindows
        set theTabs to (tabs of theWindow whose URL contains "google.com")
        repeat with theTab in theTabs
            tell theTab
                mute
            end tell
        end repeat
    end repeat
end tell

但是如果你尝试 运行 这个,你很快就会注意到 Applescript 认为 mute 是一个变量。我也试过 mute tab 但还是不行。

这应该允许选项卡静音:

tell application "Google Chrome" to activate
tell application "System Events" to ¬
    click ¬
        menu item "Mute Site" of ¬
        menu 1 of ¬
        menu bar item "Tab" of ¬
        menu bar 1 of ¬
        application process "Chrome"

GoogleChrome 中的 选项卡菜单项“静音站点”没有分配默认键盘快捷键。但是,您可以为其指定一个自定义键盘快捷键并手动使用它,或者在 AppleScript 中使用 keystrokekey code 命令。

下图显示了我如何分配自定义键盘快捷键。

正确设置自定义键盘快捷键后,下面的 AppleScript 代码就是我个人如何设置的示例。

tell application "Google Chrome" to activate

delay 0.1

tell application "System Events"
    key code 49 using {shift down, command down}
end tell