【问题标题】:How to create a menu bar toggle in Mac OSX Lion?如何在 Mac OSX Lion 中创建菜单栏切换?
【发布时间】:2011-10-15 10:16:57
【问题描述】:

如何创建一个菜单栏图标来切换麦克风静音按钮?

我会使用 AppleScript 还是 Objective-C?我在 Xcode 中创建什么样的项目(如果那是我应该使用的 IDE)。感谢您的帮助或指导。

【问题讨论】:

  • 您确定要这样做吗?键盘上有一个静音/取消静音按钮。

标签: objective-c xcode macos applescript


【解决方案1】:

试试这个...

property toggled : 0 --0 means the mic is off, 1 means the mic is on
if toggled is 0 then
    set volume input volume 100
    set toggled to 1
else
    set volume input volume 0
    set toggled to 0
end if

将此作为常规脚本文件保存在本地Library 文件夹的Scripts 文件夹中。

如果您的菜单栏中有一个看起来像滚动条的小图标(以前称为Script Menu),则该脚本应该出现在该菜单的某个位置。如果您没有看到该图标,请运行 AppleScript Utility(位于 /Applications/AppleScript/AppleScript Utility)并选中 Show Script Menu in menu bar 复选框。

现在,您只需打开脚本菜单,找到您的脚本,然后单击一次即可运行它。问题?问。 :)

【讨论】:

    【解决方案2】:

    这是一个简单的方法,因为我们可以直接获取或设置音量的输出静音属性...

    set isMuted to output muted of (get volume settings)
    if isMuted then
        set volume without output muted
    else
        set volume with output muted
    end if
    

    就设置菜单栏切换而言,按照 fireshadow52 的建议进行操作。从 AppleScript 编辑器的首选项中启用 applescript 菜单,然后将此 applescript 放在 ~/Library/Scripts 文件夹中(如果文件夹不存在,则创建该文件夹)。

    编辑:抱歉,我知道您希望麦克风静音而不是音量!我的错。

    【讨论】:

      猜你喜欢
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 2012-04-02
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多