Created
March 1, 2016 07:59
-
-
Save pvanheus/b236cae92dee77719467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# default headphone volume (40000 is 40%) | |
DEFAULT_HEADPHONE_VOLUME=${DEFAULT_HEADPHONE_VOLUME-40000} | |
# default microphone volume (80000 is 80%) | |
DEFAULT_MICROPHONE_VOLUME=${DEFAULT_MICROPHONE_VOLUME-80000} | |
# enable headphone | |
ENABLE_USB_HEADPHONE=${ENABLE_USB_HEADPHONE-1} | |
# enable microphone | |
ENABLE_USB_MICROPHONE=${ENABLE_USB_MICROPHONE-0} | |
# sleep so pulseaudio has time to enable the new sink | |
sleep 1 | |
# Use grep to figure out the name of the usb speaker | |
speaker=$(pacmd list-sinks | grep 'name:' | grep usb | sed 's/.*<//g;s/>.*//g;' | head -n 1) | |
# Use grep to figure out the name of the usb microphone | |
mic=$(pacmd list-sources | grep 'name:' | grep input | grep usb | sed 's/.*<//g;s/>.*//g;' | head -n 1) | |
if [ "z$ENABLE_USB_HEADPHONE" = "z1" ] ; then | |
if [ "z$speaker" != "z" ] | |
then | |
# use this speaker | |
pacmd set-default-sink "$speaker" | grep -vE 'Welcome|>>> $' | |
# unmute | |
pacmd set-sink-mute "$speaker" 0 | grep -vE 'Welcome|>>> $' | |
# Set the volume. 20000 is 20% | |
pacmd set-sink-volume "$speaker" $DEFAULT_HEADPHONE_VOLUME | grep -vE 'Welcome|>>> $' | |
fi | |
#play a sound to let you know that it was plugged in | |
play /usr/share/sounds/speech-dispatcher/test.wav 2> /dev/null | |
fi | |
if [ "z$ENABLE_USB_MICROPHONE" = "z1" ] ; then | |
if [ "z$mic" != "z" ] | |
then | |
# use this microphone | |
pacmd set-default-source "$mic" | grep -vE 'Welcome|>>> $' | |
# unmute | |
pacmd set-source-mute "$mic" 0 | grep -vE 'Welcome|>>> $' | |
# Set the volume. 80000 is 80% | |
pacmd set-source-volume "$mic" 80000 | grep -vE 'Welcome|>>> $' | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment