Volume Script

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

Those “on” handlers can be a roadblock to a newbie, so just in case:

you can alter the volume in a single command
set volume 1 – the number can be set from 0 (silent) to 7 (full volume)

So if you wanted to make it speakable, you could make or 4 scripts to speak.

set volume 0 – call this one “Mute Volume”

set volume 1 – call this one “Low Volume”

set volume 4 – call this one “Medium Volume”

set volume 7 – Call this one “Full Volume”

Save each line as a separate script, naming them accordingly. I’m assuming you know how to make them speakable. If not post back.
SC

Browser: Internet Explorer 5.17
Operating System: Mac OS X (10.1.x)

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)

does anyone know how i could implement this into a realbasic program when the up arrow (increase) and down arrow (decrease) are pressed? thanks!

thank you so much, WORKS. boom baby!