在Applescript中实现键盘音量控制按钮 - 在循环内设置音量不起作用

Rya*_*yne 5 applescript list

背景

我有一个MacAlly IceKey键盘.此键盘具有音量按钮,需要驱动程序才能运行.这个驱动程序自2006年以来一直没有更新,我怀疑它是最近在Mac OS X 10.6.1下遇到的反复出现的内核恐慌的根源.所以,它走了; 但是我想要我的音量键!

使用精彩的ControllerMate,我可以编写这些键来执行任何操作,包括运行applescript脚本.所以,我正在尝试实现该功能.

set volume命令(Standard Additions的一部分)允许您将音量设置为0到100之间的任何值.Apple键盘音量键允许选择总共17个音量设置(包括0).我认为复制此行为的最简单方法是保留允许的卷设置列表,并从中获取下一个最大(或最小)的设置.

问题

它不起作用.以下脚本:

set volumesList to {0, 6, 12, 18, 25, 31, 37, 43, 50, 56, 62, 68, 75, 81, 87, 93, 100}
set sysVolume to get volume settings

repeat with curVolume in volumesList
    if (curVolume > (output volume of sysVolume)) then
        set volume output volume (contents of curVolume)
        exit repeat
    end if
end repeat

get volume settings
Run Code Online (Sandbox Code Playgroud)

...仅在系统音量水平低于43时才有效.系统似乎将"50"解释为"49"; 这与我的剧本的音量一样高.如果卷开始高于50,我的脚本无效.踢球者?如果删除"退出重复"语句,系统卷将设置为100 - 正如您所期望的那样.

(好悲伤,AppleScript 有时会很奇怪.)

有任何想法吗?

奖励积分

让它显示音量叠加层也是非常棒的.有谁知道如何实现这一目标?它甚至不需要通过AppleScript; 我很高兴在命令行工具中粘贴一些Cocoa代码,如果这就是它需要的东西.

a p*_*erd 7

我不知道如何让半透明叠加显示,但这至少会在调高音量时播放系统蜂鸣声:

set currentVolume to output volume of (get volume settings)
set newVolume to (currentVolume + (100 / 17)) as integer
set volume output volume newVolume
beep
Run Code Online (Sandbox Code Playgroud)

在您的音量减小脚本中替换为+a -.

set volume output 似乎是自动调整(0,100)限制之外的值.

更新:您可以使用Growl的AppleScript支持来显示某种叠加:

tell application "GrowlHelperApp"

    register as application "Volume Change" ¬
        all notifications {"Volume Change"} ¬
        default notifications {"Volume Change"} ¬
        icon of application "Script Editor"

    notify with name "Volume Change" ¬
        title "Volume Up" ¬
        description "Volume is now " & output volume of (get volume settings) ¬
        application name "Volume Change"

end tell
Run Code Online (Sandbox Code Playgroud)