Background
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!
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.
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.
The problem
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
...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.
(Good grief, AppleScript is weird sometimes.)
Any ideas?
Bonus Points
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.
Thanks!