Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stevietheb

macrumors 6502a
Original poster
Jan 15, 2004
591
0
Houston
Howdy,

I'm a total applescript novice. What I'd like to do is create an AppleScript that gets the current output volume, and then increases it by a certain interval.

Then I'd also like to create an applescript that gets the output volume and decreases it by one.

Any suggestions? Also, are there any exhaustive online resources for AppleScript that I could exploit as I attempt to teach myself a little.

Thanks!
 
Here's some code that should help you. It uses the "get volume settings" command to get the current volume and "set volume" to set it (more information about these commands can be found in the StandardAdditions dictionary). The system uses a scale of 1..100 for volume settings, so the script converts it to a scale from 1..16 before adjusting the settings (as this scale is used when using the volume keys).

Code:
--Get the current output volume (on a scale from 1 to 100) and convert it to a scale from 1 to 16 as seen when using the volume keys
set currentVolume to output volume of (get volume settings)
set scaledVolume to round (currentVolume / (100 / 16))

--Use this code to increase the volume by a certain interval
set soundInterval to 1
set scaledVolume to scaledVolume + soundInterval
if (scaledVolume > 16) then
	set scaledVolume to 16
end if

--OR use this code to decrease the output volume by 1
set scaledVolume to scaledVolume - 1
if (scaledVolume < 0) then
	set scaledVolume to 0
end if

--After using one of the above, the volume needs to be set to the new level (before which we must convert it back to the 1..100 scale)
set newVolume to round (scaledVolume / 16 * 100)
set volume output volume newVolume
 
THANKS!!!

I figured that I needed to use the 'get volume settings' command--BUT I'm such a novice that I couldn't figure out how to get the output out of that, store it in a variable, and then increase the variable...

I'll give this a go...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.