Tuesday, September 2, 2014

#1 2005-05-08 09:05:27 pm

CalvinX
Member
Registered: 2005-05-08
Posts: 1

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)

Offline

 

#2 2005-05-08 11:16:17 pm

Camelot
Member
From: San Jose, CA
Registered: 2002-12-14
Posts: 629

Re: Volume Script

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:

Applescript:

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

Last edited by Camelot (2005-05-08 11:16:57 pm)

Offline

 

#3 2005-05-09 10:12:36 am

sitcom
Member
Registered: 2005-03-14
Posts: 367

Re: Volume Script

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)

Offline

 

#4 2005-05-09 11:49:35 am

Camelot
Member
From: San Jose, CA
Registered: 2002-12-14
Posts: 629

Re: Volume Script

set volume 1 -- the number can be set  from 0 (silent) to 7 (full volume)

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)

Offline

 

#5 2006-12-31 10:30:14 am

thopunk
Member
Registered: 2006-12-31
Posts: 2

Re: Volume Script

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

Offline

 

#6 2006-12-31 06:10:43 pm

thopunk
Member
Registered: 2006-12-31
Posts: 2

Re: Volume Script

thank you so much, WORKS. boom baby!

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.030 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)