This script will cycle to the next available audio output device. It can be tied to a hotkey to easily be triggered. This is handy, for example, for swapping between HDMI audio and headphones.
- Download the
audio-device-switch.sh
script and place it in/usr/local/bin
. - Make the script executable:
sudo chmod 755 /usr/local/bin/audio-device-switch.sh
. - Open the Keyboard Shortcuts settings page, add a new shortcut, tell it to execute
audio-device-switch.sh
, and set up your shortcut! - Install the
notify-send
library if you want to see a popup notification when the audio device switches:sudo apt install libnotify-bin
.
Feel free to modify this script and make it your own. Some ideas for customization:
Line 45 of the script calls notify-send
with the -i
flag which defines which icon is displayed. Stock icons are found in:
/usr/share/icons/gnome/32x32
/usr/share/notify-osd/icons/
Or, a custom icon file can be provided.
Line 41 fetches the output device names using the pacmd list-sinks
command and filters out the alsa.name
property. You could pull another property, such as the device.description
.
This is a more modern, robust rewrite of tsvetan's solution on the Ubuntu forums.