Last active
July 18, 2016 20:19
-
-
Save naftulikay/2a2902b850423046f3f4e57c9396e023 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
SUBSYSTEMS=="usb", ACTION=="add|change", ATTRS{idVendor}=="0d8c", ATTRS{idProduct}=="1066", RUN+="/usr/local/bin/schiit-fulla-switch added" | |
SUBSYSTEMS=="usb", ACTION=="remove", ATTRS{idVendor}=="0d8c", ATTRS{idProduct}=="1066", RUN+="/usr/local/bin/schiit-fulla-switch removed" |
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 | |
set -e | |
export DISPLAY="$(w | grep -e ^naftuli | awk '{print $3;}')" | |
if [ -z "$DISPLAY" ]; then | |
echo "No Display Found; No Active User?" >&2 | |
exit 1 | |
fi | |
function usage() { | |
echo "Usage: $0 added|removed" >&2 | |
echo "Switch the audio sink based on whether a Fulla is present." >&2 | |
exit 1 | |
} | |
if [[ "$1" != "added" && "$1" != "removed" ]]; then | |
usage | |
fi | |
speakers_grep='alsa_output.pci-0000_00_1b.0.analog-stereo' | |
schiit_grep='alsa_output.usb-Schiit_Audio_I_m_Fulla_Schiit-00-Schiit.analog-stereo' | |
function switch_audio_output() { | |
sink_id="$(pactl list short sinks | grep -e $1 | awk '{print $1;}')" | |
if [ -z "$sink_id" ]; then | |
echo "ERROR: Sink Not Found." >&2 | |
exit 1 | |
fi | |
# move all streams over to the speakers | |
pactl list short sink-inputs | awk '{print $1;}' | while read stream_id; do | |
pactl move-sink-input "$stream_id" "$sink_id" | |
done | |
# set the default sink | |
pactl set-default-sink "$sink_id" | |
return 0; | |
} | |
action="$1" | |
if [ "$action" == "added" ]; then | |
switch_audio_output $schiit_grep | |
else | |
switch_audio_output $speakers_grep | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment