How do I switch the audio outputs of an audio device from CLI?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
4
down vote
favorite
I'm trying to switch between the audio outputs of my video card from the command line. I'm able to do that via the GUI settings, as it's shown on the picture. How can I do this programmatically?
On the picture are presented two audio devices wit two outputs each:
(green) Device 1 - Built-in Audio with two outputs:
- Digital Output
- Headphones
(red)Â Â Â Â Â Device 2 - HDMI Audio Controller of NVidia GTX 660. To the video card are connected two monitors:
The first monitor is LG TV and it is connected to HDMI-0.
The second monitor is LG ULTRAWIDE and it is connected to DVI-I-1.
So I want to switch, via the command-line, between these outputs (monitors in this case). Everything I've found, in my research, is how to switch between the audio devices (sound cards). I've already read few topics as these questions:
- Audio output device, fast switch?
- How to change pulseaudio sink with "pacmd set-default-sink" during playback?
- How can I choose the audio output device using the terminal?
- How to switch sound output with key shortcut
When the first monitor LG TV | HDMI-0 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
16 alsa_output.pci-0000_03_00.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo>
- output of
pactl list sinks
- output of
pacmd list-sinks
When the second monitor LG ULTRAWIDE | DVI-I-1 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
17 alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1 module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1>
- output of
pactl list sinks
- output of
pacmd list-sinks
The output of pacmd list-cards
and pactl list cards
is provided here.
You can see (in this particular case) I'm searching for a way to switch between sink 16
and sink 17
. But when sink 16
is presented in pactl list sinks
, sink 17
is not presented and vice versa. I can switch them only from the GUI settings. Is ithere a way to do that via the command-line?
16.04 command-line pulseaudio desktop-environments
 |Â
show 2 more comments
up vote
4
down vote
favorite
I'm trying to switch between the audio outputs of my video card from the command line. I'm able to do that via the GUI settings, as it's shown on the picture. How can I do this programmatically?
On the picture are presented two audio devices wit two outputs each:
(green) Device 1 - Built-in Audio with two outputs:
- Digital Output
- Headphones
(red)Â Â Â Â Â Device 2 - HDMI Audio Controller of NVidia GTX 660. To the video card are connected two monitors:
The first monitor is LG TV and it is connected to HDMI-0.
The second monitor is LG ULTRAWIDE and it is connected to DVI-I-1.
So I want to switch, via the command-line, between these outputs (monitors in this case). Everything I've found, in my research, is how to switch between the audio devices (sound cards). I've already read few topics as these questions:
- Audio output device, fast switch?
- How to change pulseaudio sink with "pacmd set-default-sink" during playback?
- How can I choose the audio output device using the terminal?
- How to switch sound output with key shortcut
When the first monitor LG TV | HDMI-0 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
16 alsa_output.pci-0000_03_00.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo>
- output of
pactl list sinks
- output of
pacmd list-sinks
When the second monitor LG ULTRAWIDE | DVI-I-1 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
17 alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1 module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1>
- output of
pactl list sinks
- output of
pacmd list-sinks
The output of pacmd list-cards
and pactl list cards
is provided here.
You can see (in this particular case) I'm searching for a way to switch between sink 16
and sink 17
. But when sink 16
is presented in pactl list sinks
, sink 17
is not presented and vice versa. I can switch them only from the GUI settings. Is ithere a way to do that via the command-line?
16.04 command-line pulseaudio desktop-environments
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
orpactl set-default-sink alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
?
â Thomas
Mar 4 at 15:10
@Thomas, if I understood your suggestion correctly the result isFailure: No such entity
.
â pa4080
Mar 4 at 15:21
There is not sinkalsa_output.pci-0000_03_00.1.hdmi-stereo
butalsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
. Don't get the point from your link?
â Thomas
Mar 4 at 15:25
@Thomas, I've updated the question.
â pa4080
Mar 4 at 15:43
Ah, got it...sorry. I think you have to change the profile as well. Can you test withpactl set-card-profile 1 hdmi-stereo
and see if the sink list changes. After that you should be able to change to the...stereo
sink. If not, please also add the output ofpactl list cards short
.
â Thomas
Mar 4 at 16:11
 |Â
show 2 more comments
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'm trying to switch between the audio outputs of my video card from the command line. I'm able to do that via the GUI settings, as it's shown on the picture. How can I do this programmatically?
On the picture are presented two audio devices wit two outputs each:
(green) Device 1 - Built-in Audio with two outputs:
- Digital Output
- Headphones
(red)Â Â Â Â Â Device 2 - HDMI Audio Controller of NVidia GTX 660. To the video card are connected two monitors:
The first monitor is LG TV and it is connected to HDMI-0.
The second monitor is LG ULTRAWIDE and it is connected to DVI-I-1.
So I want to switch, via the command-line, between these outputs (monitors in this case). Everything I've found, in my research, is how to switch between the audio devices (sound cards). I've already read few topics as these questions:
- Audio output device, fast switch?
- How to change pulseaudio sink with "pacmd set-default-sink" during playback?
- How can I choose the audio output device using the terminal?
- How to switch sound output with key shortcut
When the first monitor LG TV | HDMI-0 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
16 alsa_output.pci-0000_03_00.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo>
- output of
pactl list sinks
- output of
pacmd list-sinks
When the second monitor LG ULTRAWIDE | DVI-I-1 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
17 alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1 module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1>
- output of
pactl list sinks
- output of
pacmd list-sinks
The output of pacmd list-cards
and pactl list cards
is provided here.
You can see (in this particular case) I'm searching for a way to switch between sink 16
and sink 17
. But when sink 16
is presented in pactl list sinks
, sink 17
is not presented and vice versa. I can switch them only from the GUI settings. Is ithere a way to do that via the command-line?
16.04 command-line pulseaudio desktop-environments
I'm trying to switch between the audio outputs of my video card from the command line. I'm able to do that via the GUI settings, as it's shown on the picture. How can I do this programmatically?
On the picture are presented two audio devices wit two outputs each:
(green) Device 1 - Built-in Audio with two outputs:
- Digital Output
- Headphones
(red)Â Â Â Â Â Device 2 - HDMI Audio Controller of NVidia GTX 660. To the video card are connected two monitors:
The first monitor is LG TV and it is connected to HDMI-0.
The second monitor is LG ULTRAWIDE and it is connected to DVI-I-1.
So I want to switch, via the command-line, between these outputs (monitors in this case). Everything I've found, in my research, is how to switch between the audio devices (sound cards). I've already read few topics as these questions:
- Audio output device, fast switch?
- How to change pulseaudio sink with "pacmd set-default-sink" during playback?
- How can I choose the audio output device using the terminal?
- How to switch sound output with key shortcut
When the first monitor LG TV | HDMI-0 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
16 alsa_output.pci-0000_03_00.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo>
- output of
pactl list sinks
- output of
pacmd list-sinks
When the second monitor LG ULTRAWIDE | DVI-I-1 is engaged as audio output:
$ pactl list sinks short
8 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
17 alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1 module-alsa-card.c s16le 2ch 44100Hz RUNNING
$ pacmd list-sinks | grep name:
name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
name: <alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1>
- output of
pactl list sinks
- output of
pacmd list-sinks
The output of pacmd list-cards
and pactl list cards
is provided here.
You can see (in this particular case) I'm searching for a way to switch between sink 16
and sink 17
. But when sink 16
is presented in pactl list sinks
, sink 17
is not presented and vice versa. I can switch them only from the GUI settings. Is ithere a way to do that via the command-line?
16.04 command-line pulseaudio desktop-environments
16.04 command-line pulseaudio desktop-environments
edited Mar 6 at 19:29
asked Mar 4 at 15:00
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12.3k52256
12.3k52256
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
orpactl set-default-sink alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
?
â Thomas
Mar 4 at 15:10
@Thomas, if I understood your suggestion correctly the result isFailure: No such entity
.
â pa4080
Mar 4 at 15:21
There is not sinkalsa_output.pci-0000_03_00.1.hdmi-stereo
butalsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
. Don't get the point from your link?
â Thomas
Mar 4 at 15:25
@Thomas, I've updated the question.
â pa4080
Mar 4 at 15:43
Ah, got it...sorry. I think you have to change the profile as well. Can you test withpactl set-card-profile 1 hdmi-stereo
and see if the sink list changes. After that you should be able to change to the...stereo
sink. If not, please also add the output ofpactl list cards short
.
â Thomas
Mar 4 at 16:11
 |Â
show 2 more comments
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
orpactl set-default-sink alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
?
â Thomas
Mar 4 at 15:10
@Thomas, if I understood your suggestion correctly the result isFailure: No such entity
.
â pa4080
Mar 4 at 15:21
There is not sinkalsa_output.pci-0000_03_00.1.hdmi-stereo
butalsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
. Don't get the point from your link?
â Thomas
Mar 4 at 15:25
@Thomas, I've updated the question.
â pa4080
Mar 4 at 15:43
Ah, got it...sorry. I think you have to change the profile as well. Can you test withpactl set-card-profile 1 hdmi-stereo
and see if the sink list changes. After that you should be able to change to the...stereo
sink. If not, please also add the output ofpactl list cards short
.
â Thomas
Mar 4 at 16:11
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
or pactl set-default-sink alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
?â Thomas
Mar 4 at 15:10
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
or pactl set-default-sink alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
?â Thomas
Mar 4 at 15:10
@Thomas, if I understood your suggestion correctly the result is
Failure: No such entity
.â pa4080
Mar 4 at 15:21
@Thomas, if I understood your suggestion correctly the result is
Failure: No such entity
.â pa4080
Mar 4 at 15:21
There is not sink
alsa_output.pci-0000_03_00.1.hdmi-stereo
but alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
. Don't get the point from your link?â Thomas
Mar 4 at 15:25
There is not sink
alsa_output.pci-0000_03_00.1.hdmi-stereo
but alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
. Don't get the point from your link?â Thomas
Mar 4 at 15:25
@Thomas, I've updated the question.
â pa4080
Mar 4 at 15:43
@Thomas, I've updated the question.
â pa4080
Mar 4 at 15:43
Ah, got it...sorry. I think you have to change the profile as well. Can you test with
pactl set-card-profile 1 hdmi-stereo
and see if the sink list changes. After that you should be able to change to the ...stereo
sink. If not, please also add the output of pactl list cards short
.â Thomas
Mar 4 at 16:11
Ah, got it...sorry. I think you have to change the profile as well. Can you test with
pactl set-card-profile 1 hdmi-stereo
and see if the sink list changes. After that you should be able to change to the ...stereo
sink. If not, please also add the output of pactl list cards short
.â Thomas
Mar 4 at 16:11
 |Â
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
Thanks to the discussion with @Thomas I realised the proper therms (key words) are profile and card. In the terms of the question profiles are the inputs and outputs. The cards are the audio devices. And the sink numbers are not so important, but we need them.
We can find all available profiles for each card name by the command pacmd list-cards
or pactl list cards
that outputs the same information:
$ pactl list cards
Card #0
Name: alsa_card.pci-0000_00_1b.0
...
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
output:analog-surround-21: Analog Surround 2.1 Output (sinks: 1, sources: 0, priority: 800, available: yes)
...
Active Profile: output:iec958-stereo+input:analog-stereo
...
Card #1
Name: alsa_card.pci-0000_03_00.1
...
Profiles:
output:hdmi-stereo: Digital Stereo (HDMI) Output (sinks: 1, sources: 0, priority: 5400, available: yes)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (sinks: 1, sources: 0, priority: 5200, available: yes)
output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
...
Active Profile: output:hdmi-stereo
...
A certain profile can be set by command with format as this:
pactl set-card-profile output:hdmi-stereo <card name|number> <profile name>
According to the question for the four mentioned outputs the commands are:
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo # LG ULTRAWIDE
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo-extra1 # LG TV
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:iec958-stereo # Digital Output
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo # Headphones
As it is shown in this answer, when the new profile is set next things to do are:
pacmd set-default-sink <sink number of the target profile>
pacmd move-sink-input "$i" <sink number of the target profile>
# where $i is the index number of any active input: pacmd list-sink-inputs
According to my needs, described in the question, I've created the following script:
#!/bin/bash
# Name: /usr/local/bin/audioswitch
# Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4
CARD_1="pci-0000_03_00.1" ### HDMI Audio Controller of NVidia GTX 660
CARD_1_PROFILE_1="hdmi-stereo" # LG ULTRAWIDE
CARD_1_PROFILE_2="hdmi-stereo-extra1" # LG TV
CARD_0="pci-0000_00_1b.0" ### Built-in Audio
CARD_0_PROFILE_1="iec958-stereo" # Digital Output
CARD_0_PROFILE_2="analog-stereo" # Headphones
# Read the user's input
CHOICE="$@"
choice()
if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE
elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV
elif [ "$CHOICE" == 3 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_1" # Digital Output
elif [ "$CHOICE" == 4 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_2" # Headphones
else
echo -e "nYou should choice between:"
echo -e "nt[1] LG ULTRAWIDEnt[2] LG TVnt[3] Digital Outputnt[4] Headphonesn"
echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again
fi
; choice # call the function
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.$CARD" "output:$PROF";
# Set the default sink to the new one
pacmd set-default-sink "alsa_output.$CARD.$PROF" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk 'print $2'); do
pacmd move-sink-input "$i" "alsa_output.$CARD.$PROF" &> /dev/null
done
The script is ready to be used with custom keyboard shortcuts, because it can handle the value (1
-4
) of the first positional parameter. When it is called without additional paraneter it will ask for your choice:
$ audioswitch
You should choice between:
[1] LG ULTRAWIDE
[2] LG TV
[3] Digital Output
[4] Headphones
Your choice: 1
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Thanks to the discussion with @Thomas I realised the proper therms (key words) are profile and card. In the terms of the question profiles are the inputs and outputs. The cards are the audio devices. And the sink numbers are not so important, but we need them.
We can find all available profiles for each card name by the command pacmd list-cards
or pactl list cards
that outputs the same information:
$ pactl list cards
Card #0
Name: alsa_card.pci-0000_00_1b.0
...
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
output:analog-surround-21: Analog Surround 2.1 Output (sinks: 1, sources: 0, priority: 800, available: yes)
...
Active Profile: output:iec958-stereo+input:analog-stereo
...
Card #1
Name: alsa_card.pci-0000_03_00.1
...
Profiles:
output:hdmi-stereo: Digital Stereo (HDMI) Output (sinks: 1, sources: 0, priority: 5400, available: yes)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (sinks: 1, sources: 0, priority: 5200, available: yes)
output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
...
Active Profile: output:hdmi-stereo
...
A certain profile can be set by command with format as this:
pactl set-card-profile output:hdmi-stereo <card name|number> <profile name>
According to the question for the four mentioned outputs the commands are:
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo # LG ULTRAWIDE
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo-extra1 # LG TV
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:iec958-stereo # Digital Output
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo # Headphones
As it is shown in this answer, when the new profile is set next things to do are:
pacmd set-default-sink <sink number of the target profile>
pacmd move-sink-input "$i" <sink number of the target profile>
# where $i is the index number of any active input: pacmd list-sink-inputs
According to my needs, described in the question, I've created the following script:
#!/bin/bash
# Name: /usr/local/bin/audioswitch
# Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4
CARD_1="pci-0000_03_00.1" ### HDMI Audio Controller of NVidia GTX 660
CARD_1_PROFILE_1="hdmi-stereo" # LG ULTRAWIDE
CARD_1_PROFILE_2="hdmi-stereo-extra1" # LG TV
CARD_0="pci-0000_00_1b.0" ### Built-in Audio
CARD_0_PROFILE_1="iec958-stereo" # Digital Output
CARD_0_PROFILE_2="analog-stereo" # Headphones
# Read the user's input
CHOICE="$@"
choice()
if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE
elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV
elif [ "$CHOICE" == 3 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_1" # Digital Output
elif [ "$CHOICE" == 4 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_2" # Headphones
else
echo -e "nYou should choice between:"
echo -e "nt[1] LG ULTRAWIDEnt[2] LG TVnt[3] Digital Outputnt[4] Headphonesn"
echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again
fi
; choice # call the function
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.$CARD" "output:$PROF";
# Set the default sink to the new one
pacmd set-default-sink "alsa_output.$CARD.$PROF" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk 'print $2'); do
pacmd move-sink-input "$i" "alsa_output.$CARD.$PROF" &> /dev/null
done
The script is ready to be used with custom keyboard shortcuts, because it can handle the value (1
-4
) of the first positional parameter. When it is called without additional paraneter it will ask for your choice:
$ audioswitch
You should choice between:
[1] LG ULTRAWIDE
[2] LG TV
[3] Digital Output
[4] Headphones
Your choice: 1
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
add a comment |Â
up vote
4
down vote
accepted
Thanks to the discussion with @Thomas I realised the proper therms (key words) are profile and card. In the terms of the question profiles are the inputs and outputs. The cards are the audio devices. And the sink numbers are not so important, but we need them.
We can find all available profiles for each card name by the command pacmd list-cards
or pactl list cards
that outputs the same information:
$ pactl list cards
Card #0
Name: alsa_card.pci-0000_00_1b.0
...
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
output:analog-surround-21: Analog Surround 2.1 Output (sinks: 1, sources: 0, priority: 800, available: yes)
...
Active Profile: output:iec958-stereo+input:analog-stereo
...
Card #1
Name: alsa_card.pci-0000_03_00.1
...
Profiles:
output:hdmi-stereo: Digital Stereo (HDMI) Output (sinks: 1, sources: 0, priority: 5400, available: yes)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (sinks: 1, sources: 0, priority: 5200, available: yes)
output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
...
Active Profile: output:hdmi-stereo
...
A certain profile can be set by command with format as this:
pactl set-card-profile output:hdmi-stereo <card name|number> <profile name>
According to the question for the four mentioned outputs the commands are:
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo # LG ULTRAWIDE
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo-extra1 # LG TV
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:iec958-stereo # Digital Output
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo # Headphones
As it is shown in this answer, when the new profile is set next things to do are:
pacmd set-default-sink <sink number of the target profile>
pacmd move-sink-input "$i" <sink number of the target profile>
# where $i is the index number of any active input: pacmd list-sink-inputs
According to my needs, described in the question, I've created the following script:
#!/bin/bash
# Name: /usr/local/bin/audioswitch
# Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4
CARD_1="pci-0000_03_00.1" ### HDMI Audio Controller of NVidia GTX 660
CARD_1_PROFILE_1="hdmi-stereo" # LG ULTRAWIDE
CARD_1_PROFILE_2="hdmi-stereo-extra1" # LG TV
CARD_0="pci-0000_00_1b.0" ### Built-in Audio
CARD_0_PROFILE_1="iec958-stereo" # Digital Output
CARD_0_PROFILE_2="analog-stereo" # Headphones
# Read the user's input
CHOICE="$@"
choice()
if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE
elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV
elif [ "$CHOICE" == 3 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_1" # Digital Output
elif [ "$CHOICE" == 4 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_2" # Headphones
else
echo -e "nYou should choice between:"
echo -e "nt[1] LG ULTRAWIDEnt[2] LG TVnt[3] Digital Outputnt[4] Headphonesn"
echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again
fi
; choice # call the function
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.$CARD" "output:$PROF";
# Set the default sink to the new one
pacmd set-default-sink "alsa_output.$CARD.$PROF" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk 'print $2'); do
pacmd move-sink-input "$i" "alsa_output.$CARD.$PROF" &> /dev/null
done
The script is ready to be used with custom keyboard shortcuts, because it can handle the value (1
-4
) of the first positional parameter. When it is called without additional paraneter it will ask for your choice:
$ audioswitch
You should choice between:
[1] LG ULTRAWIDE
[2] LG TV
[3] Digital Output
[4] Headphones
Your choice: 1
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Thanks to the discussion with @Thomas I realised the proper therms (key words) are profile and card. In the terms of the question profiles are the inputs and outputs. The cards are the audio devices. And the sink numbers are not so important, but we need them.
We can find all available profiles for each card name by the command pacmd list-cards
or pactl list cards
that outputs the same information:
$ pactl list cards
Card #0
Name: alsa_card.pci-0000_00_1b.0
...
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
output:analog-surround-21: Analog Surround 2.1 Output (sinks: 1, sources: 0, priority: 800, available: yes)
...
Active Profile: output:iec958-stereo+input:analog-stereo
...
Card #1
Name: alsa_card.pci-0000_03_00.1
...
Profiles:
output:hdmi-stereo: Digital Stereo (HDMI) Output (sinks: 1, sources: 0, priority: 5400, available: yes)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (sinks: 1, sources: 0, priority: 5200, available: yes)
output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
...
Active Profile: output:hdmi-stereo
...
A certain profile can be set by command with format as this:
pactl set-card-profile output:hdmi-stereo <card name|number> <profile name>
According to the question for the four mentioned outputs the commands are:
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo # LG ULTRAWIDE
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo-extra1 # LG TV
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:iec958-stereo # Digital Output
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo # Headphones
As it is shown in this answer, when the new profile is set next things to do are:
pacmd set-default-sink <sink number of the target profile>
pacmd move-sink-input "$i" <sink number of the target profile>
# where $i is the index number of any active input: pacmd list-sink-inputs
According to my needs, described in the question, I've created the following script:
#!/bin/bash
# Name: /usr/local/bin/audioswitch
# Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4
CARD_1="pci-0000_03_00.1" ### HDMI Audio Controller of NVidia GTX 660
CARD_1_PROFILE_1="hdmi-stereo" # LG ULTRAWIDE
CARD_1_PROFILE_2="hdmi-stereo-extra1" # LG TV
CARD_0="pci-0000_00_1b.0" ### Built-in Audio
CARD_0_PROFILE_1="iec958-stereo" # Digital Output
CARD_0_PROFILE_2="analog-stereo" # Headphones
# Read the user's input
CHOICE="$@"
choice()
if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE
elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV
elif [ "$CHOICE" == 3 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_1" # Digital Output
elif [ "$CHOICE" == 4 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_2" # Headphones
else
echo -e "nYou should choice between:"
echo -e "nt[1] LG ULTRAWIDEnt[2] LG TVnt[3] Digital Outputnt[4] Headphonesn"
echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again
fi
; choice # call the function
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.$CARD" "output:$PROF";
# Set the default sink to the new one
pacmd set-default-sink "alsa_output.$CARD.$PROF" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk 'print $2'); do
pacmd move-sink-input "$i" "alsa_output.$CARD.$PROF" &> /dev/null
done
The script is ready to be used with custom keyboard shortcuts, because it can handle the value (1
-4
) of the first positional parameter. When it is called without additional paraneter it will ask for your choice:
$ audioswitch
You should choice between:
[1] LG ULTRAWIDE
[2] LG TV
[3] Digital Output
[4] Headphones
Your choice: 1
Thanks to the discussion with @Thomas I realised the proper therms (key words) are profile and card. In the terms of the question profiles are the inputs and outputs. The cards are the audio devices. And the sink numbers are not so important, but we need them.
We can find all available profiles for each card name by the command pacmd list-cards
or pactl list cards
that outputs the same information:
$ pactl list cards
Card #0
Name: alsa_card.pci-0000_00_1b.0
...
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
output:analog-surround-21: Analog Surround 2.1 Output (sinks: 1, sources: 0, priority: 800, available: yes)
...
Active Profile: output:iec958-stereo+input:analog-stereo
...
Card #1
Name: alsa_card.pci-0000_03_00.1
...
Profiles:
output:hdmi-stereo: Digital Stereo (HDMI) Output (sinks: 1, sources: 0, priority: 5400, available: yes)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (sinks: 1, sources: 0, priority: 5200, available: yes)
output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
...
Active Profile: output:hdmi-stereo
...
A certain profile can be set by command with format as this:
pactl set-card-profile output:hdmi-stereo <card name|number> <profile name>
According to the question for the four mentioned outputs the commands are:
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo # LG ULTRAWIDE
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo-extra1 # LG TV
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:iec958-stereo # Digital Output
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo # Headphones
As it is shown in this answer, when the new profile is set next things to do are:
pacmd set-default-sink <sink number of the target profile>
pacmd move-sink-input "$i" <sink number of the target profile>
# where $i is the index number of any active input: pacmd list-sink-inputs
According to my needs, described in the question, I've created the following script:
#!/bin/bash
# Name: /usr/local/bin/audioswitch
# Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4
CARD_1="pci-0000_03_00.1" ### HDMI Audio Controller of NVidia GTX 660
CARD_1_PROFILE_1="hdmi-stereo" # LG ULTRAWIDE
CARD_1_PROFILE_2="hdmi-stereo-extra1" # LG TV
CARD_0="pci-0000_00_1b.0" ### Built-in Audio
CARD_0_PROFILE_1="iec958-stereo" # Digital Output
CARD_0_PROFILE_2="analog-stereo" # Headphones
# Read the user's input
CHOICE="$@"
choice()
if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE
elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV
elif [ "$CHOICE" == 3 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_1" # Digital Output
elif [ "$CHOICE" == 4 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_2" # Headphones
else
echo -e "nYou should choice between:"
echo -e "nt[1] LG ULTRAWIDEnt[2] LG TVnt[3] Digital Outputnt[4] Headphonesn"
echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again
fi
; choice # call the function
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.$CARD" "output:$PROF";
# Set the default sink to the new one
pacmd set-default-sink "alsa_output.$CARD.$PROF" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk 'print $2'); do
pacmd move-sink-input "$i" "alsa_output.$CARD.$PROF" &> /dev/null
done
The script is ready to be used with custom keyboard shortcuts, because it can handle the value (1
-4
) of the first positional parameter. When it is called without additional paraneter it will ask for your choice:
$ audioswitch
You should choice between:
[1] LG ULTRAWIDE
[2] LG TV
[3] Digital Output
[4] Headphones
Your choice: 1
edited Mar 6 at 21:06
answered Mar 6 at 21:00
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12.3k52256
12.3k52256
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
add a comment |Â
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
Notes for further improvements: 1; 2; 3.
â pa4080
Mar 20 at 11:10
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1011806%2fhow-do-i-switch-the-audio-outputs-of-an-audio-device-from-cli%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
orpactl set-default-sink alsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
?â Thomas
Mar 4 at 15:10
@Thomas, if I understood your suggestion correctly the result is
Failure: No such entity
.â pa4080
Mar 4 at 15:21
There is not sink
alsa_output.pci-0000_03_00.1.hdmi-stereo
butalsa_output.pci-0000_03_00.1.hdmi-stereo-extra1
. Don't get the point from your link?â Thomas
Mar 4 at 15:25
@Thomas, I've updated the question.
â pa4080
Mar 4 at 15:43
Ah, got it...sorry. I think you have to change the profile as well. Can you test with
pactl set-card-profile 1 hdmi-stereo
and see if the sink list changes. After that you should be able to change to the...stereo
sink. If not, please also add the output ofpactl list cards short
.â Thomas
Mar 4 at 16:11