Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A shell script to mute volume for a set length of time UNIX
Here's a script to mute the system volume for a given amount of time, then unmute it after that period of time. This is very useful, for instance, for skipping 30-second commercials.
#!/bin/tcsh -f # -V -X

#% tcsh script, wrapping around osascript/applescript,
#% for muting the volume for set amount of time (or infinite if no argument).
#% type 'mute 30 &' to mute for 30 seconds.
#%
#% (c) 2005 chris.wiggins(at)gmail.com 

if ( $# == "0" ) then
  osascript -e "set volume 0"
else
  osascript -e "set volume 0"
  sleep $1
  osascript -e "set volume 10"
endif
[robg adds: I tested this, and though it worked, when it restores the volume, it sets it to maximum. So I went out Googling, and found (I think) a nicer way (thanks to Bo in the comments) to do the same thing. Here's my version of the script. Each of the osascript lines should be one long line; I broke them to make it narrower. Just remove the line breaks...
if ( $# == "0" ) then
  osascript -e 'tell application "System Events" to set volume 
   with output muted'
else
  osascript -e 'tell application "System Events" to set volume 
   with output muted'
  sleep $1
  osascript -e 'tell application "System Events" to set volume 
   without output muted'
endif
This works as above, but has the advantage of restoring the volume to its previous level, instead of coming back at maximum. Remember to make the script executable, and store it somewhere on your PATH.]
    •    
  • Currently 2.33 / 5
  You rated: 5 / 5 (6 votes cast)
 
[10,988 views]  

A shell script to mute volume for a set length of time | 3 comments | Create New Account
Click here to return to the 'A shell script to mute volume for a set length of time' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A shell script to mute volume for a set length of time
Authored by: rwmitchell on Jul 07, '05 12:50:12PM

Everyone's a critic...

You can make the script a little shorter by changing the order of the statements:


#!/bin/csh
osascript -e 'tell application "System Events" to set volume with output muted'
if ( $# != "0" ) then
sleep $1
osascript -e 'tell application "System Events" to set volume without output muted'
endif


That gets rid of one duplicate line.



[ Reply to This | # ]
A shell script to mute volume for a set length of time
Authored by: EvenStranger on Jul 11, '05 12:12:29PM

Used in reverse, this would be a good script to keep in mind for next April Fool's Day, perhaps combined with a particularly embarassing sound file. Jack up the volume, play sound, revert volume.

Ok, it's juvenile, but what's April 1 for if not to be a little juvenile?

EvenStranger (thirty something, going on twelve)



[ Reply to This | # ]
A shell script to mute volume for a set length of time
Authored by: jacobolus on Jan 13, '06 01:32:06PM
If we want it even shorter still, the tell block isn't necessary:

#!/bin/csh
osascript -e 'set volume with output muted'
if ( $# != "0" ) then
sleep $1
osascript -e 'set volume without output muted'
endif


[ Reply to This | # ]