Linux: Shortcuts to change audio output
🔉

Linux: Shortcuts to change audio output

Author
André Arruda
Tags
Linux
Shortcuts
Personal
Slug
Published
Aug 11, 2023
Tag

DEFAULT OUTPUT

Create file

sudo gnome-text-editor /usr/local/bin/audio-analog.sh
#!/bin/bash

sink_names=($(pactl list short sinks | awk '{print $2}'))

# Loop through each sink name
for sink_name in "${sink_names[@]}"; do
    if [[ "$sink_name" == *"analog-stereo"* ]]; then
        pactl set-default-sink "$sink_name"
        echo "Default sink set to: $sink_name"
        break  # Exit the loop once the first matching sink is found
    fi
done

notify-send --hint int:transient:1 'DEFAULT audio output' --icon=multimedia-volume-control		

Make created file as executable

sudo chmod 755 /usr/local/bin/audio-analog.sh

Add custom shortcut

  • System -> Preferences -> Keyboard Shortcuts
  • Press Add
  • Name: DEFAULT
  • Command: audio-analog.sh
  • Shortcut: Super + F7
 
notion image
 

HDMI OUTPUT

Create file

sudo gnome-text-editor /usr/local/bin/audio-hdmi.sh
#!/bin/bash

sink_names=($(pactl list short sinks | awk '{print $2}'))

# Loop through each sink name
for sink_name in "${sink_names[@]}"; do
    if [[ "$sink_name" == *"hdmi-stereo"* ]]; then
        pactl set-default-sink "$sink_name"
        echo "Default sink set to: $sink_name"
        break  # Exit the loop once the first matching sink is found
    fi
done

notify-send --hint int:transient:1 'HDMI audio output' --icon=multimedia-volume-control

Make created file as executable

sudo chmod 755 /usr/local/bin/audio-hdmi.sh

Add custom shortcut

  • System -> Preferences -> Keyboard Shortcuts
  • Press Add
  • Name: DEFAULT
  • Command: audio-hdmi.sh
  • Shortcut: Super + F7
 
 

BLUETOOTH OUTPUT

Create file

sudo gnome-text-editor /usr/local/bin/audio-bluetooth.sh
#!/bin/bash

sink_names=($(pactl list short sinks | awk '{print $2}'))

# Loop through each sink name
for sink_name in "${sink_names[@]}"; do
    if [[ "$sink_name" == *"bluez_output"* ]]; then
        pactl set-default-sink "$sink_name"
        echo "Default sink set to: $sink_name"
        break  # Exit the loop once the first matching sink is found
    fi
done

notify-send --hint int:transient:1 'BLUETOOTH audio output' --icon=multimedia-volume-control		

Make created file as executable

sudo chmod 755 /usr/local/bin/audio-bluetooth.sh

Add custom shortcut

  • System -> Preferences -> Keyboard Shortcuts
  • Press Add
  • Name: BLUETOOTH
  • Command: audio-bluetooth.sh
  • Shortcut: Super + F8