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 speakers and headphones.
This script will work on systems running PulseAudio or Pipewire services.
- 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 83 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/
This is a more modern, robust rewrite of tsvetan's solution on the Ubuntu forums.
Thank you. With your corrections, it works great. It's a shame that the author didn't fix it.