I am recently reall new to Applescript and have been messing around with it a bit. I was wondering if anyone could write me a script that I could use in Voice Recognition for Volume. One that I could say " Volume Up" or “Volume Down” or “Mute” and it would do it. I don’t know if this is even possible but if it is I would be very thankful for any help. If there isn’t a way to do this, is there a way to bind the volume buttons on my Apple keyboard to other commands such as Apple + 1 or something like that? Thanks for the help.
-Calvin
Browser: Safari 312
Operating System: Mac OS X (10.4)
It’s fairly trivial to write volume up/down controls. The issue is that you have to query the current setting to know what to set it to - you can’t just tell AppleScript ‘volume up’, you have to tell it what new volume setting to use.
These handlers will turn the volume up or down by 10% each time they’re called, or toggle the mute settings. You can save them as separate scripts if you want to call them independently:
on volumeUp()
-- script to raise the volume
-- get the current setting
set curVolume to output volume of (get volume settings)
-- work out the new setting
if curVolume < 90 then
set newVolume to curVolume + 10
else
-- can't go over 100
set newVolume to 100
end if
-- and apply it
set volume output volume newVolume
end volumeUp
on volumeDown()
-- script to lower the volume
-- get current volume level
set curVolume to output volume of (get volume settings)
-- work out the new setting
if curVolume > 10 then
set newVolume to curVolume - 10
else
-- can't go lower than 1
set newVolume to 1
end if
-- and apply it
set volume output volume newVolume
end volumeDown
on volumeMute()
-- script to toggle the mute setting
-- get the current mute setting
set isMuted to output muted of (get volume settings)
-- invert it
set newMuted to not isMuted
-- and set it back
set volume output muted newMuted
end volumeMute
The ‘set volume x’ syntax is listed as deprecated, in favor of the newer 1-100 scale used by ‘set volume output volume x’. It’s not a good habit to start off using deprecated commands.
On that basis you don’t want to use a series of fixed scale scripts because you’d end up with 100 different ‘set volume’ scripts for all possible sound levels. A relative script that increases or decreases from the current setting is more portable.
Browser: Safari 412
Operating System: Mac OS X (10.3.7)