I have two audio outputs: one is a wireless headset, the other is my laptop's built-in 3.5mm jack. How do I switch between them via the terminal? Ultimately, I want to assign a keyboard shortcut to do the switch.
Asked
Active
Viewed 335 times
0
-
1Similar question, maybe a duplicate: http://askubuntu.com/questions/71863/how-to-change-pulseaudio-sink-with-pacmd-set-default-sink-during-playback/72076#72076 – wjandrea Jul 24 '16 at 20:28
1 Answers
0
I built a script which does the switching. I call it using xbindkeys
. I'm sure it could be improved, because I'm not very good with grep, and it's not ideal that the script works on the basis of numbers instead of names. The script is big because it takes a lot of effort to automate the process, but here are the essential parts:
# Identify any active sink inputs (audio streams - identified by number).
pacmd list-sink-inputs
# Identify the next sink (output - identified by number or by name).
pacmd list-sinks
# Switch the sink input to the next sink.
pactl move-sink-input "$sink_input" "$next_sink"
# Change the default sink to the next one.
pactl set-default-sink "$next_sink"

wjandrea
- 14,236
- 4
- 48
- 98
-
The script doesn't always work 100%. Sometimes it switches the device to the wrong one, and it won't switch inactive sink inputs. So now I'm using a GUI toggle program,
indicator-sound-switcher
, available here. – wjandrea May 27 '16 at 18:31 -
indicator-sound-switcher
also won't switch an inactive input. Still looking for an ideal solution... – wjandrea Jul 12 '16 at 18:30