【问题标题】:Trigger Specific Menubar Icon with Keyboard on Mac在 Mac 上使用键盘触发特定菜单栏图标
【发布时间】:2014-12-17 07:21:28
【问题描述】:

我想在不使用鼠标的情况下触发 MenuBar 应用程序。 CopyClip 是确切应用程序的名称。我在网上找到的只是 Ctrl-F2 或 Ctrl-F8 这些都不允许访问您在菜单栏中下载的应用程序。我已经尝试这样做了好几个星期。 BetterTouchTool 不允许此类操作。我猜我需要写一个小applescript来做到这一点,但不知道如何得到任何帮助或指导。

既然图片在这里说话就是我想要的。

【问题讨论】:

  • 菜单栏是 SystemUIServer 核心服务的一部分,我没有在其中看到任何 AppleScript 字典。如果您喜欢冒险,可以通过将自己的代码注入到 -[NSMenuToolbar _setCurrentMenuItem:] 方法中来玩转它,但这不适合胆小的人。

标签: macos applescript keyboard-shortcuts menubar osx-yosemite


【解决方案1】:

您必须对其进行修改以适合您的特定应用。

在脚本编辑器中单独运行这些并检查结果:

tell application "System Events" to menu bar items of every menu bar of ¬
    process "SystemUIServer"

.

tell application "System Events" to value of attributes of menu bar items of menu bar 1 of ¬
    process "SystemUIServer"

.

tell application "System Events" to value of attributes of menu bar 1 of ¬
    process "BetterTouchTool"

从 BetterTouchTool 中单击首选项的方法如下:

tell application "System Events" to tell process "BetterTouchTool"
    click first menu bar item of menu bar 1
    click menu item 1 of menu 1 of menu bar item of menu bar 1
end tell

在 AirPort 中关闭 WiFi 的方法如下:

tell application "System Events" to tell process "SystemUIServer"
    click (first menu bar item whose value of attribute "AXDescription" contains "Wi-Fi") ¬
        of menu bar 1
    try
        click menu item 2 of menu of ¬
            (first menu bar item whose value of attribute "AXDescription" contains "Wi-Fi") of ¬
            menu bar 1
    end try
end tell

Accessibility Inspector 是你的朋友。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-22
    • 2013-01-24
    • 2010-09-13
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多