A shell script to mute volume for a set length of time
Jul 07, '05 09:05:00AM • Contributed by: Anonymous
Jul 07, '05 09:05:00AM • Contributed by: Anonymous
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.]
•
[11,024 views]
