This is my first post here at bashscripts.org, I have been looking around the site for awhile, and have been meaning to get some of my personal scripts up, I have some more, I just need to get around to posting them. Let me know what you think of this one.
This is a simple script I wrote to turn on/off the sound output to my headset and surround sound. I wrote it because I got sick of turning my surround sound unit off to use headsets, and music playing on headsets when surround sound is in use. It should work for anyone, but it may require some tweaking, PM me if you need any help with getting it to work for you. Also this is a more complex version compared to the original, I can post the original aswell, I added arrays and loops to this one.
Code:
#!/bin/bash
#todo: ----
#make it toggle
#
#Usage ./$0 [options]
# -h will play the output on the headset
# -s will play the output on the surround sound
#An Array holding the three values of my surround sound output for amixer.
surround=(Surround Center Side)
surround_cnt=${#surround[*]}
#evaluate command line arguments.
while [ $# -gt 0 ]
do
case "$1" in
"-s")
#mute the headset output
amixer -c 0 sset Front mute > /dev/null
#unmute the surround sound outputs.
for ((i=0;i<$surround_cnt;i++))
do
amixer -c 0 sset ${surround[$i]} unmute > /dev/null
done
;;
"-h")
#unmute the headset output
amixer -c 0 sset Front unmute > /dev/null
#mute the surround sound outputs.
for ((i=0;i<$surround_cnt;i++))
do
amixer -c 0 sset ${surround[$i]} mute > /dev/null
done
;;
esac
shift
done