How to quickly switch sound output devices?
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
How to quickly switch sound output devices?
Hi all!
I'm using LM18.1 with Cinnamon 3.2.7.
One of the common tasks that I do multiple times per day is to switch between audio outputs. I sometimes like to send the sound to my speakers and sometimes to my headphones. The way I've been doing it now is to select output in Sound part of System Settings. It's tedious and takes too many clicks. Is there an applet that would allow me to quickly switch outputs? Or maybe some way to assign this to a keyboard shortcut? Maybe command line?
Thanks for any tips!
Dave
I'm using LM18.1 with Cinnamon 3.2.7.
One of the common tasks that I do multiple times per day is to switch between audio outputs. I sometimes like to send the sound to my speakers and sometimes to my headphones. The way I've been doing it now is to select output in Sound part of System Settings. It's tedious and takes too many clicks. Is there an applet that would allow me to quickly switch outputs? Or maybe some way to assign this to a keyboard shortcut? Maybe command line?
Thanks for any tips!
Dave
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How to quickly switch sound output devices?
Here it happens automatically when plugging in the headphones.
Check out the alsa mixer settings for automute.
in a terminal:
Check out the alsa mixer settings for automute.
in a terminal:
Code: Select all
alsamixer
Everything in life was difficult before it became easy.
Re: How to quickly switch sound output devices?
Take a look at pavucontrol.
Re: How to quickly switch sound output devices?
Have you considered a hardware solution? A couple of months ago I've bought a switch. It cost me 24 Australian dollars delivered. Now I can switch between four outputs with one light push of an index finger. I love it.
Also worth keeping in mind, by piggybacking one switch onto another you could switch between four inputs on one and four outputs on the other.
The switch I have is small, tucks in comfortably under my main monitor and looks like this:
Also worth keeping in mind, by piggybacking one switch onto another you could switch between four inputs on one and four outputs on the other.
The switch I have is small, tucks in comfortably under my main monitor and looks like this:
Re: How to quickly switch sound output devices?
Someone made a script to do this. I don't remember where I found this to give proper credit.
This script cycles through your sound devices:
If you want to switch to a specific device, I used parts of that script to just pick a particular device:
This is for my particular audio device. You'd have to replace the devicename="" with your own device.
To find your device name, open a terminal and enter:
The devices will be listed as index: 0, index: 1, etc.
Underneath each 'index' there is an entry something like:
name: <alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio-00.analog-stereo>
Grab the text in the angled brackets and paste it into devicename="".
You can save the script as an .sh file and run it any way you like.
To make switching quicker, you can assign the script to a shortcut key.
Menu --> System Settings --> Keyboard --> Shortcuts --> Custom Shortcuts --> Add custom shortcut --> select the script you just made
For me, I like to assign a few different audio outputs to CTRL+F9, CTRL+F10 to select between my DAC and my bluetooth headphones.
This script cycles through your sound devices:
Code: Select all
#!/bin/bash
declare -i sinks_count=`pacmd list-sinks | grep -c index:[[:space:]][[:digit:]]`
declare -i active_sink_index=`pacmd list-sinks | sed -n -e 's/\*[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`
declare -i major_sink_index=$sinks_count-1
declare -i next_sink_index=0
if [ $active_sink_index -ne $major_sink_index ] ; then
next_sink_index=active_sink_index+1
fi
#change the default sink
pacmd "set-default-sink ${next_sink_index}"
#move all inputs to the new sink
for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p');
do
pacmd "move-sink-input $app $next_sink_index"
done
#display notification
declare -i ndx=0
pacmd list-sinks | sed -n -e 's/device.description[[:space:]]=[[:space:]]"\(.*\)"/\1/p' | while read line;
do
if [ $next_sink_index -eq $ndx ] ; then
notify-send -i notification-audio-volume-high "Sound output switched to" "$line"
exit
fi
ndx+=1
done;
Code: Select all
#!/bin/bash
#Device name variable
devicename="alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio-00.analog-stereo"
#change the default sink
pacmd "set-default-sink "$devicename""
#move all inputs to the new sink
for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p');
do
pacmd "move-sink-input $app "$devicename""
done
To find your device name, open a terminal and enter:
Code: Select all
pacmd list-sinks
Underneath each 'index' there is an entry something like:
name: <alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio-00.analog-stereo>
Grab the text in the angled brackets and paste it into devicename="".
You can save the script as an .sh file and run it any way you like.
To make switching quicker, you can assign the script to a shortcut key.
Menu --> System Settings --> Keyboard --> Shortcuts --> Custom Shortcuts --> Add custom shortcut --> select the script you just made
For me, I like to assign a few different audio outputs to CTRL+F9, CTRL+F10 to select between my DAC and my bluetooth headphones.
Re: How to quickly switch sound output devices?
Hi "DaveJones",
I just read your post and the good replies to it. Here are my thoughts on this as well.
FYI: There are some really nice graphical (GUI) programs for sound that start with "Qas", like the fantastic "Qasmixer", in the Software Manager or Synaptic Package Manager (SPM) that you can install and use. Sound "Mixers" can be a little confusing if you are not familiar with them. If you bring up "Qasmixer" and make it fullscreen, on the right side you will have mixer devices where you can control your system sound. If you do not see the mixer devices, hit "F6". The mixer item "sysdefault" will show all installed sound card devices, and you will have various options to adjust various volume controls using "sliders" which you can turn off and on using the "dot" below the volume slider. There are also various other check boxes below that you can use, and depending upon your sound card(s) that sometimes includes headphone checkboxes and or sliders as well, like "Headphone Jack Sense".
The applications included are:
- qasconfig - browser for the alsa configuration tree
- qashctl - mixer for alsa's high level control interface
- qasmixer - desktop mixer with features similar to alsamixer
Qasmixer is a desktop mixer application for alsa's "simple mixer interface" and offers features similar to alsamixer. it also features a sytem tray icon with basic mixer functionality.
Install "libasound2-plugin-equal" which is another system wide equalizer that's in the Software Manager or Synaptic Package Manager (SPM) that shows up in "QasMixer".
Hope this helps ...
I just read your post and the good replies to it. Here are my thoughts on this as well.
FYI: There are some really nice graphical (GUI) programs for sound that start with "Qas", like the fantastic "Qasmixer", in the Software Manager or Synaptic Package Manager (SPM) that you can install and use. Sound "Mixers" can be a little confusing if you are not familiar with them. If you bring up "Qasmixer" and make it fullscreen, on the right side you will have mixer devices where you can control your system sound. If you do not see the mixer devices, hit "F6". The mixer item "sysdefault" will show all installed sound card devices, and you will have various options to adjust various volume controls using "sliders" which you can turn off and on using the "dot" below the volume slider. There are also various other check boxes below that you can use, and depending upon your sound card(s) that sometimes includes headphone checkboxes and or sliders as well, like "Headphone Jack Sense".
The applications included are:
- qasconfig - browser for the alsa configuration tree
- qashctl - mixer for alsa's high level control interface
- qasmixer - desktop mixer with features similar to alsamixer
Qasmixer is a desktop mixer application for alsa's "simple mixer interface" and offers features similar to alsamixer. it also features a sytem tray icon with basic mixer functionality.
Install "libasound2-plugin-equal" which is another system wide equalizer that's in the Software Manager or Synaptic Package Manager (SPM) that shows up in "QasMixer".
Hope this helps ...
Phd21: Mint 20 Cinnamon & KDE Neon 64-bit Awesome OS's, Dell Inspiron I5 7000 (7573, quad core i5-8250U ) 2 in 1 touch screen
Re: How to quickly switch sound output devices?
Thank you!
My laptop has an unused button and I can assign the script execution to this button. exactly what I've looked for.
My laptop has an unused button and I can assign the script execution to this button. exactly what I've looked for.
ugly wrote:Someone made a script to do this. I don't remember where I found this to give proper credit.
Re: How to quickly switch sound output devices?
Hi Ugly,ugly wrote:Someone made a script to do this. I don't remember where I found this to give proper credit.
This script cycles through your sound devices:If you want to switch to a specific device, I used parts of that script to just pick a particular device:Code: Select all
#!/bin/bash declare -i sinks_count=`pacmd list-sinks | grep -c index:[[:space:]][[:digit:]]` declare -i active_sink_index=`pacmd list-sinks | sed -n -e 's/\*[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'` declare -i major_sink_index=$sinks_count-1 declare -i next_sink_index=0 if [ $active_sink_index -ne $major_sink_index ] ; then next_sink_index=active_sink_index+1 fi #change the default sink pacmd "set-default-sink ${next_sink_index}" #move all inputs to the new sink for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p'); do pacmd "move-sink-input $app $next_sink_index" done #display notification declare -i ndx=0 pacmd list-sinks | sed -n -e 's/device.description[[:space:]]=[[:space:]]"\(.*\)"/\1/p' | while read line; do if [ $next_sink_index -eq $ndx ] ; then notify-send -i notification-audio-volume-high "Sound output switched to" "$line" exit fi ndx+=1 done;
This is for my particular audio device. You'd have to replace the devicename="" with your own device.Code: Select all
#!/bin/bash #Device name variable devicename="alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio-00.analog-stereo" #change the default sink pacmd "set-default-sink "$devicename"" #move all inputs to the new sink for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p'); do pacmd "move-sink-input $app "$devicename"" done
To find your device name, open a terminal and enter:The devices will be listed as index: 0, index: 1, etc.Code: Select all
pacmd list-sinks
Underneath each 'index' there is an entry something like:
name: <alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio-00.analog-stereo>
Grab the text in the angled brackets and paste it into devicename="".
You can save the script as an .sh file and run it any way you like.
To make switching quicker, you can assign the script to a shortcut key.
Menu --> System Settings --> Keyboard --> Shortcuts --> Custom Shortcuts --> Add custom shortcut --> select the script you just made
For me, I like to assign a few different audio outputs to CTRL+F9, CTRL+F10 to select between my DAC and my bluetooth headphones.
Can this switch between speakers and 3.5 fron headphone jack? For whatever reason this didn't work for me with the analog sound (and I have no use for HDMI just yet and it's disabled). Made a somewhat simpler toggler and attached it to a launcher:
Code: Select all
#! /bin/bash
set_slusalice() {
pacmd set-sink-port 0 analog-output-headphones
amixer set Front 0%
pactl set-sink-volume 0 50%
}
set_zvucnici() {
pacmd set-sink-port 0 analog-output-lineout
pactl set-sink-volume 0 30%
}
AKTIVAN=$(pacmd list | grep "<analog-output-lineout>" | cut -f3 -d ' ')
if [ "$AKTIVAN" == "<analog-output-lineout>" ]
then
set_slusalice
else
set_zvucnici
fi
Re: How to quickly switch sound output devices?
Unfortunately, I've quickly bumped in a bug I couldn't live with in the script quoted by ugly. Every time i had removed my USB headset, the script stopped working and kept switching to the analog output from itself until the restart of my laptop.
I've found an another script that working almost without a bug. It also keeps circle-toggle the outputs. There is minor bug in (if it is a bug), but I can live with it. If remove the USB headset while the output is on the USB device then put it back again I have to click 2 times the button assigned to the script to switch to the analog output. It will work just fine thereafter again.
I rather prefer the new script for one more reason, because the previous one kept popping up notification with every action and having a new notification entry in the history too.
here is the new script:
credit goes for Gaco and user512557
original source: https://askubuntu.com/questions/71863/h ... g-playback
I've found an another script that working almost without a bug. It also keeps circle-toggle the outputs. There is minor bug in (if it is a bug), but I can live with it. If remove the USB headset while the output is on the USB device then put it back again I have to click 2 times the button assigned to the script to switch to the analog output. It will work just fine thereafter again.
I rather prefer the new script for one more reason, because the previous one kept popping up notification with every action and having a new notification entry in the history too.
here is the new script:
Code: Select all
#!/bin/bash
new_sink=$(pacmd list-sinks | grep index | tee /dev/stdout | grep -m1 -A1 "* index" | tail -1 | cut -c12-)
echo "Setting default sink to: $new_sink";
pacmd set-default-sink $new_sink
pacmd list-sink-inputs | grep index | while read line
do
echo "Moving input: ";
echo $line | cut -f2 -d' ';
echo "to sink: $new_sink";
pacmd move-sink-input `echo $line | cut -f2 -d' '` $new_sink
done
credit goes for Gaco and user512557
original source: https://askubuntu.com/questions/71863/h ... g-playback
Re: How to quickly switch sound output devices?
i know the thread is old but i also one of the guys that switch from internal soundcard (with desktop speakers) to my usb headset (that has an own soundcard device). If u hit the right mousebutton on the speaker icon u can switch ur sound devices realy fast. not as fast as an keyboard shortcut but i can live with this functionality.
Re: How to quickly switch sound output devices?
#!/bin/bash
# This toggles the line-out to headphones and vice versa
# Linux Mint Mate 18.3 Tested and Works
# Save this as a script file and make sure it is set to "Allow executing file as a program" in the permissions
# Create a launcher and put on panel to use it.
#
# There is a hidden char in front of __active port: <analog-output>"*" so you have to include it
# Find which output is the active one
test_output=$(pacmd info | grep -i " active port: <analog-output>"*)
if [[ "$test_output" = " active port: <analog-output-lineout>" ]] ; then
pacmd set-sink-port 1 "analog-output-headphones" ;
elif [[ "$test_output" = " active port: <analog-output-headphones>" ]] ; then
pacmd set-sink-port 1 "analog-output-lineout" ;
fi # commands I have use to figure this out (don't use root)
# don't include the following in script
$ pacmd info | grep -i "active"
active port: <hdmi-output-0>
active port: <analog-output-headphones>
active profile: <output:hdmi-surround>
active profile: <output:analog-stereo>
me@mint-18 ~/Desktop $ ./headphone
active port: <analog-output-headphones> (notice the extra tab or space at the beginning of this output line)
$ pacmd info | grep -i "active port: <analog-output-"*
active port: <analog-output-lineout>
$ pacmd info | grep -i "active port: <analog-output-"*
active port: <analog-output-headphones>
# This toggles the line-out to headphones and vice versa
# Linux Mint Mate 18.3 Tested and Works
# Save this as a script file and make sure it is set to "Allow executing file as a program" in the permissions
# Create a launcher and put on panel to use it.
#
# There is a hidden char in front of __active port: <analog-output>"*" so you have to include it
# Find which output is the active one
test_output=$(pacmd info | grep -i " active port: <analog-output>"*)
if [[ "$test_output" = " active port: <analog-output-lineout>" ]] ; then
pacmd set-sink-port 1 "analog-output-headphones" ;
elif [[ "$test_output" = " active port: <analog-output-headphones>" ]] ; then
pacmd set-sink-port 1 "analog-output-lineout" ;
fi # commands I have use to figure this out (don't use root)
# don't include the following in script
$ pacmd info | grep -i "active"
active port: <hdmi-output-0>
active port: <analog-output-headphones>
active profile: <output:hdmi-surround>
active profile: <output:analog-stereo>
me@mint-18 ~/Desktop $ ./headphone
active port: <analog-output-headphones> (notice the extra tab or space at the beginning of this output line)
$ pacmd info | grep -i "active port: <analog-output-"*
active port: <analog-output-lineout>
$ pacmd info | grep -i "active port: <analog-output-"*
active port: <analog-output-headphones>
Re: How to quickly switch sound output devices?
Big thanks to you! Would've been better, IMO, if the left click on Sound applet show those option by default but its better than to switch the output device from System Settings -> Sound -> Output tab.mayo83 wrote: ⤴Tue Aug 08, 2017 2:59 pm i know the thread is old but i also one of the guys that switch from internal soundcard (with desktop speakers) to my usb headset (that has an own soundcard device). If u hit the right mousebutton on the speaker icon u can switch ur sound devices realy fast. not as fast as an keyboard shortcut but i can live with this functionality.
Re: How to quickly switch sound output devices?
Guys I found a better solution to this Install so called Indicator Sound Switcher, it works like an applet and is very easy,customizable. I'm using it in Linux Mint 19.1 (works great). Here links:
https://www.omgubuntu.co.uk/2016/09/ind ... buntu-snap
https://github.com/yktoo/indicator-sound-switcher
https://www.omgubuntu.co.uk/2016/09/ind ... buntu-snap
https://github.com/yktoo/indicator-sound-switcher