【问题标题】:OSX tick menu bar checkboxOSX 勾选菜单栏复选框
【发布时间】:2018-06-28 01:56:53
【问题描述】:

对于我的应用程序MuteSpotifyAds,我不想添加自动启用私人会话模式的功能。

为此,我不想在 OSX 菜单栏的菜单 Spotify 中切换菜单栏项目 Private Session。我使用以下applescript,它有效:

来源:https://stackoverflow.com/a/16497564/6286431

tell application "System Events" to tell process "Spotify" tell menu bar item 2 of menu bar 0 click click menu item "Private Session" of menu 1 end tell end tell

问题是我必须检查复选框是否已经打勾,否则我会禁用Private Session

有没有办法检查菜单复选框是否已经打勾?

我已经尝试过this,但似乎只适用于实际窗口中的复选框。

如果你有不使用applescript的解决方案,那也很好!

【问题讨论】:

    标签: macos applescript spotify


    【解决方案1】:

    菜单项是否被选中的信息在菜单项的属性“AXMenuItemMarkChar”中

    tell application "System Events" to tell process "Spotify"
        tell menu bar item 2 of menu bar 1 -- AppleScript indexes are 1-based
            tell menu item "Private Session" of menu 1
                set isChecked to value of attribute "AXMenuItemMarkChar" is "✓"
                if not isChecked then click it
            end tell
        end tell
    end tell
    

    【讨论】:

    • 完美运行!
    猜你喜欢
    • 2010-12-15
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 2020-06-16
    • 1970-01-01
    相关资源
    最近更新 更多