实施AppleScript的键盘的音量控制按钮 - 设置内部循环量无效 [英] Implementing keyboard volume control buttons in Applescript - setting volume inside loop doesn't work

查看:288
本文介绍了实施AppleScript的键盘的音量控制按钮 - 设置内部循环量无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我有一个Macally在IceKey键盘。该键盘有需要的驱动程序的功能音量按钮。该驱动程序尚未自2006年更新的,我怀疑它作为一个经常性最近的内核崩溃,我一直在Mac OS X 10.6.1经历的争吵的根源。因此,出于它去;但我想我的音量键回来了!

I have a MacAlly IceKey keyboard. This keyboard has volume buttons that require a driver to function. This driver has not been updated since 2006, and I suspect it as the source of a recent spat of recurring kernel panics I've been experiencing under Mac OS X 10.6.1. So, out it goes; but I want my volume keys back!

使用 ControllerMate ,我可以将这些按键进行编程,以做任何事情,包括运行AppleScript脚本。所以,我想实现这个功能。

Using the wonderful ControllerMate, I can program these keys to do anything, including run an applescript script. So, I'm trying to implement that functionality.

设定的音量命令(标准添加的一部分),您可以将音量设置为任意值介于0和100之间的Apple键盘的音量键允许共有17个音量设置进行选择(包括0)。我想复制这种行为最简单的方法就是保持容​​许音量设置列表,并抓住下一个最大(或最小)的一出这一点。

The set volume command (part of Standard Additions) allows you to set the volume to any value between 0 and 100. The Apple keyboard volume keys allow a total of 17 volume settings to be selected (including 0). I figure the simplest way to duplicate this behavior is to keep a list of allowed volume settings and grab the next largest (or smallest) one out of that.

问题

这是行不通的。下面的脚本:

It doesn't work. The following script:

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

...如果系统音量电平刚好是小于43的系统,似乎间$ P $角50为49只适用;这是一样高的容量将与我的脚本走。如果卷的启动的高于50,我的剧本没有任何效果。踢球?如果退出重复的声明被删除,系统音量被设置为100 - 正如你所期望的。

...only works if the system volume level happens to be less than 43. The system seems to interpret "50" as "49"; that's as high as the volume will go with my script. If the volume starts higher than 50, my script has no effect. The kicker? If the "exit repeat" statement is removed, the system volume gets set to 100 - just as you'd expect.

(天哪,AppleScript的是的怪异的时候。)

(Good grief, AppleScript is weird sometimes.)

任何想法?

奖励积分

这将是超真棒得到这个显示音量覆盖为好。有谁知道如何实现这一目标?它甚至不需要通过AppleScript的;我很高兴坚持一个命令行工具,一些可可code,如果这是什么需要。

It would be super awesome to get this to display the volume overlay as well. Does anyone know how to accomplish that? It doesn't even need to be through AppleScript; I'm happy sticking some Cocoa code in a command-line tool if that's what it takes.

谢谢!

推荐答案

我不知道怎么去半透明叠加显示出来,但是这至少播放而打开卷的系统发出哔哔声:

I have no idea how to get the translucent overlay to show up, but this at least plays the system beep while turning the volume up:

set currentVolume to output volume of (get volume settings)
set newVolume to (currentVolume + (100 / 17)) as integer
set volume output volume newVolume
beep

替换 + - 在你的音量降低脚本

设定的音量输出看来(0,100)的限制之外进行自动调整的值。

set volume output seems to be automatically adjust values outside the (0, 100) limit.

更新:的你可以使用低吼的AppleScript的支持显示的部分的一种叠加的:

Update: You could use Growl's AppleScript support to show some kind of overlay:

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

这篇关于实施AppleScript的键盘的音量控制按钮 - 设置内部循环量无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆