Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Emulating volume keys with AppleScripts

Emulating volume keys with AppleScripts
Thread Tools
Mac Elite
Join Date: Mar 2000
Location: Cambridge
Status: Offline
Reply With Quote
Feb 1, 2001, 10:49 PM
 
Does any one know if there is a way to create AppleScripts that will increase and decrease the volume incrementally. I have an old keyboard for my iMac and like the size but wouldn't mind having the new volume feature of the new keyboards. If possible, I would write the scripts and then bind them to the function keys. I would like there to be only two scripts and not one for every major volume setting.
Per Square Mile | A blog about density
     
RGS
Guest
Status:
Reply With Quote
Feb 3, 2001, 07:40 PM
 
Requires Jon's Commands OSAX.

Note: The small integer volume control pre-OS9.1 used to be 0-7. Now with OS9.1 it appears to be 0-8... can anyone else confirm this?

To increase the volume by increments of 1:

tell application "Finder"
set myVol to sound volume --Jon's Commands
if myVol is less than or equal to 7 then
set sound volume to myVol + 1
end if
end tell


To decrease the volume by increments of 1:

tell application "Finder"
set myVol to sound volume --Jon's Commands
if myVol is greater than or equal to 1 then
set sound volume to myVol - 1
end if
end tell
     
RGS
Guest
Status:
Reply With Quote
Feb 4, 2001, 10:24 AM
 
Update: I'm not sure how long Sound Scripting (OS9.1) has been a MAC OS scripting addition but you can set the volume without having Jon's Commands. The scripts for the most part are the same.

To increase the volume by increments of 1:

tell application "Sound Scripting"
set myVol to sound volume
if myVol is less than or equal to 7 then
set sound volume to myVol + 1
end if
end tell

tell application "Sound Scripting" to quit


To decrease the volume by increments of 1:

tell application "Sound Scripting"
set myVol to sound volume
if myVol is greater than or equal to 1 then
set sound volume to myVol - 1
end if
end tell

tell application "Sound Scripting" to quit
     
Mac Elite
Join Date: Mar 2000
Location: Cambridge
Status: Offline
Reply With Quote
Feb 4, 2001, 04:54 PM
 
Wow! Thanks for the advice and the scripts. I've tried them both out and they work great!
Per Square Mile | A blog about density
     
Senior User
Join Date: May 2000
Location: Australia
Status: Offline
Reply With Quote
Feb 4, 2001, 05:55 PM
 
Hey, great scripts RGS.

And if you want to make it beep so you know how loud it is:
after the last line, just put in beep. like this:

tell application "Sound Scripting" to quit
beep

It's not really needed, but some people like to know how loud they are making it. Just a personal preference for some people.
     
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
Feb 5, 2001, 12:58 PM
 
Hi all,

Just wanted to note that, in addition to the excellent advice given by RGS above, there's yet another older 'FadeAway' scripting addition (OSAX) which apparently can also perform this task (and can even separately set the individual left/right channel levels). [See the earlier related Sound volumes thread in this Forum; note that its link to the 'FadeAway' OSAX is old, and should now instead be FadeAway.]

Regards,

--Paul
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2