User Tools

Site Tools


ubuntu:sound:pulseaudio:set_default_sound_output_card

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
ubuntu:sound:pulseaudio:set_default_sound_output_card [2020/12/13 12:08] โ€“ peterubuntu:sound:pulseaudio:set_default_sound_output_card [2020/12/13 12:23] (current) โ€“ peter
Line 45: Line 45:
  
 ---- ----
 +
 +===== Use a BASH Script =====
 +
 +<code bash>
 +!/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
 +</code>
 +
 +**NOTE:**  
 +
 +Before running the script:
 +
 +  * Set Permissions: <code bash>sudo chmod 755 /usr/local/bin/audio-device-switch.sh</code>
 +
 +To allocate to a shortcut key:
 +
 +  * Navigate to **System -> Preferences -> Keyboard Shortcuts**.
 +  * Click **Add**.
 +    * Name:  **Switch between audio devices**.
 +    * Command:  **audio-device-switch.sh**.
 +    * Press Apply.
 +    * Select the newly added shortcut row and click on the shortcut column.
 +    * Choose a shortcut combination โ€“ e.g.WIN + F12.
 +
 +
 +
 +
 +----
 +
  
 ===== References ===== ===== References =====
  
 man pactl man pactl
ubuntu/sound/pulseaudio/set_default_sound_output_card.1607861315.txt.gz ยท Last modified: 2020/12/13 12:08 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki