Last active
November 28, 2015 01:25
-
-
Save dhhdev/e38eae4a5598774dd031 to your computer and use it in GitHub Desktop.
Automaticly switch currently running sink-inputs to your default (selected fall-back) output device.
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 | |
# Dependencies: pulseaudio | |
# Optional: pavucontrol | |
# Automaticly switch currently running sink-inputs to your default sink. | |
# $ pactl set-default-sink | |
# Pavucontrol can be used to do this with a GUI. | |
# Special thanks goes to Steve Parker for helping me with refining the script. | |
# URL: http://www.steve-parker.org | |
function update { | |
pactl list short sink-inputs | while read PID PSINKID dump | |
do | |
# Get Default Sink (Name) | |
DSINKNAME=$(pactl info | grep "^Default Sink:" | awk '{ print $3 }') | |
# Get Playback Sink (Name) of currently playing sink-input(s) | |
PSINKNAME=$(pactl list short sinks | grep "^$PSINKID" | awk '{ print $2 }') | |
# If currently playing (playback stream) input sink != default sink. | |
# Then move the sink-input to the default sink. | |
[ $DSINKNAME != $PSINKNAME ] && pactl move-sink-input $PID @DEFAULT_SINK@ | |
done | |
} | |
# Subscribe and listen for changes to device output | |
pactl subscribe | while read EVENT ETYPE dump SOURCE dump | |
do | |
# If there are detected changes, update the sinks | |
[ $ETYPE = "'change'" ] && [ $SOURCE = "server" ] && update | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment