如何使用没有媒体控制的键盘来控制 OS X 上的系统音量?

如何使用没有媒体控制的键盘来控制 OS X 上的系统音量?

我在 Mac OS 上使用 PC 键盘。我可以使用菜单栏来控制音量,但是有没有什么键盘快捷键可以用来更改系统音量?

或者也许我可以安装一个简单的脚本或解决方案,以便能够使用键盘设置音量。

答案1

您可以购买专业版炙手可热的钥匙。它preference pane允许您定义自定义键盘快捷键以修改系统音量以及执行许多其他操作。


或者,您可以使用 AppleScript 修改系统音量。

打开 AppleScript 编辑器并输入

set volume output volume 100

音量范围是 0 到 100。您可以设置一个绝对值(例如 100 表示最大音量),也可以创建增加/减少的脚本,如下所示:

set vol to output volume of (get volume settings)
if vol > 90 then # 100 max
    set volume output volume 100
else
    set volume output volume (vol + 10)
end if

降低音量:

set vol to output volume of (get volume settings)
if vol < 10 then # 0 is min
    set volume output volume 0
else
    set volume output volume (vol - 10)
end if

如果您想复制改变音量时通常会发生的反馈声音,您可以将以下内容添加到脚本中:

    do shell script "afplay /System/Library/Sounds/Pop.aiff"

您可以将脚本另存为应用程序,或将其集成到服务菜单使用 Automator 作为无输入服务。您可以在系统偏好设置 » 键盘 » 键盘快捷键 » 服务

答案2

登山扣(原名 KeyRemap4MacBook)可以重新映射功能键来控制音量,到目前为止对我来说运行顺畅。在控制面板中,搜索“F9 静音”等。

答案3

我打包了一套 AppleScript 服务和指令,让您可以在 Lion 中的任何键盘上控制系统和 iTunes 音量,以及播放/暂停和下一个/上一个。

http://gskinner.com/blog/archives/2011/10/media-keys-in-osx-for-any-keyboard.html

答案4

以下是我关于音量调高、调低和静音快捷键的完整解决方案。我使用火花应用程序将按键组合绑定到这些脚本。脚本会检查当前的静音状态并进行处理,以避免因控制不当而发生的奇怪问题。

提高音量:

set vol to output muted of (get volume settings)
if (vol = true) then
    set volume without output muted
end if
set vol to output volume of (get volume settings)
if vol > 95 then
    set volume output volume 100
else
    set volume output volume (vol + 5)
end if

do shell script "afplay /System/Library/Sounds/Pop.aiff"

音量减小:

set vol to output muted of (get volume settings)
if (vol = true) then
    error number -128
else
    set vol to output volume of (get volume settings)
    if vol < 5 then # 0 is min
        set volume with output muted
    else
        set volume output volume (vol - 5)
    end if

    do shell script "afplay /System/Library/Sounds/Pop.aiff"

end if

静音/取消静音:

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

相关内容