Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created May 15, 2025 00:48
Show Gist options
  • Save jbrechtel/ba488022d8585111a2833d3a410fbb07 to your computer and use it in GitHub Desktop.
Save jbrechtel/ba488022d8585111a2833d3a410fbb07 to your computer and use it in GitHub Desktop.
#!/bin/sh
#pacmd set-default-sink alsa_output.usb-Logitech_Logitech_G933_Gaming_Wireless_Headset-00.analog-stereo
#pacmd set-default-source alsa_input.usb-Logitech_Logitech_G933_Gaming_Wireless_Headset-00.analog-mono
set -e
QUDELIX_SINK="alsa_output.usb-QTIL_Qudelix-5K_USB_DAC_ABCDEF0123456789-00.analog-stereo"
SPEAKER_SINK="alsa_output.pci-0000_0f_00.4.3.iec958-stereo"
STAGE_SINK="alsa_output.usb-ACTIONS_Stage_V2-00.analog-stereo"
BOSE_SINK="bluez_output.78_2B_64_CE_04_03.1"
YETI_SOURCE="alsa_input.usb-Blue_Microphones_Yeti_Nano_2231SQ0017G8_888-000476140106-00.analog-stereo"
switchAudio() {
case "$1" in
"-s")
#echo -en "Firefox\0icon\x1ffirefox" | fuzzel --dmenu
echo -e "qudelix\0icon\x1faudio-headphones"
#echo "qudelix"
echo -e "stage\0icon\x1faudio-speakers"
#echo "stage"
echo -e "bose\0icon\x1fbluetooth"
exit 0;
;;
"qudelix")
local sink="$QUDELIX_SINK"
local source="$YETI_SOURCE"
;;
"speakers")
local sink="$SPEAKER_SINK"
local source="$YETI_SOURCE"
;;
"stage")
local sink="$STAGE_SINK"
local source="$YETI_SOURCE"
;;
"bose")
local sink="$BOSE_SINK"
local source="$YETI_SOURCE"
;;
esac;
local sourceCommand="pactl move-source-output {} $source"
local sinkCommand="pactl move-sink-input {} $sink"
pactl set-default-sink $sink
pactl list | grep -o -E 'Sink Input #([0-9]+)' | cut -d"#" -f2 | xargs -I '{}' $sinkCommand
#pactl list | grep -o -E 'Source Output #([0-9]+)' | cut -d"#" -f2 | xargs -I '{}' $sourceCommand
pactl set-default-source $source
echo $1 > $HOME/.last_audio
notify-send -a "Audio" "Switched to $1"
}
nextAudio() {
local last_audio=$(cat $HOME/.last_audio)
case "$last_audio" in
"qudelix")
local next="speakers"
;;
"speakers")
local next="qudelix"
;;
*)
local next="qudelix"
;;
esac;
switchAudio $next
}
case "$1" in
"next")
nextAudio
;;
*)
switchAudio $1
;;
esac;
#!/usr/bin/nu
let qudelix_sink = "alsa_output.usb-QTIL_Qudelix-5K_USB_DAC_ABCDEF0123456789-00.5.analog-stereo"
let stage_sink = "alsa_output.usb-ACTIONS_Stage_V2-00.5.analog-stereo"
let bose_sink = "bluez_output.78_2B_64_CE_04_03.1"
let yeti_source = "alsa_input.usb-Blue_Microphones_Yeti_Nano_2231SQ0017G8_888-000476140106-00.5.analog-stereo"
let searches = [{ name: "qudelix" output: "qudelix" input: "yeti" }
{ name: "stage" output: "stage" input: "yeti" }
{ name: "bose" output: "78_2B_64_CE_04_03" input: "78_2B_64_CE_04_03" }]
def switchAudio [outputName: string] {
let searchFields = ($searches | where name == $outputName | first)
let sink = findDeviceByName $searchFields.output "output"
let source = findDeviceByName $searchFields.input "input"
print $sink
print $source
print $"pactl set-default-sink _($sink)_"
#print ("pactl set-default-source " ++ $source)
sh -c $"pactl set-default-sink ($sink)"
#sh -c "pactl set-default-source ${source}"
#notify-send -a "Audio" ("Switched to " ++ $searchFields.output)
#notify-send -a "Audio" ("Switched to " ++ $searchFields.output ++ " and " ++ $searchFields.input)
}
def main [
output?: string
--list (-l):
] {
if $list {
$searches | each { |output| $output.name } | to text
} else {
switchAudio $output
}
}
def findDeviceByName [type: string, description: string]: string -> string {
pactl list | find "Name: " | find $type | find $description | find -v monitor | parse "{field}: {device}" | get device.0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment