added audio output toggle
This commit is contained in:
33
.config/polybar/audio_output_status.sh
Executable file
33
.config/polybar/audio_output_status.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the ID of the default sink (output device)
|
||||
default_sink=$(wpctl status 2>/dev/null | awk '/Sinks:/,/Sources:/' | awk '/\*/ {print $3}' | tr -d '.')
|
||||
|
||||
if [ -z "$default_sink" ]; then
|
||||
echo "No default audio output device found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the description or fallback to node.name
|
||||
device_name=$(wpctl inspect "$default_sink" 2>/dev/null | awk -F '"' '/node.description/ {print $2}')
|
||||
|
||||
if [ -z "$device_name" ]; then
|
||||
device_name=$(wpctl inspect "$default_sink" 2>/dev/null | awk -F '"' '/node.name/ {print $2}')
|
||||
fi
|
||||
|
||||
# Map known device names to labels
|
||||
case "$device_name" in
|
||||
"Starship/Matisse HD Audio Controller Analog Stereo")
|
||||
label="Speakers"
|
||||
;;
|
||||
"Yeti Stereo Microphone Analog Stereo")
|
||||
label="Earphones"
|
||||
;;
|
||||
*)
|
||||
label="$device_name"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Output the label
|
||||
echo "$label"
|
||||
|
||||
48
.config/polybar/audio_output_switch.sh
Executable file
48
.config/polybar/audio_output_switch.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to get the ID of the default sink
|
||||
get_default_sink_id() {
|
||||
wpctl status | awk '/Sinks:/,/Sources:/' | awk '/\*/ {print $3}' | tr -d '.'
|
||||
}
|
||||
|
||||
# Function to get the description of a sink by ID
|
||||
get_sink_description() {
|
||||
wpctl inspect "$1" | awk -F '"' '/node.description/ {print $2}'
|
||||
}
|
||||
|
||||
# Get current default sink ID
|
||||
current_sink_id=$(get_default_sink_id)
|
||||
|
||||
# If no sink found, exit
|
||||
if [ -z "$current_sink_id" ]; then
|
||||
echo "No default audio output device found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get its description
|
||||
current_description=$(get_sink_description "$current_sink_id")
|
||||
|
||||
# Decide target device name based on current device
|
||||
case "$current_description" in
|
||||
"Starship/Matisse HD Audio Controller Analog Stereo")
|
||||
target_description="Yeti Stereo Microphone Analog Stereo"
|
||||
;;
|
||||
"Yeti Stereo Microphone Analog Stereo")
|
||||
target_description="Starship/Matisse HD Audio Controller Analog Stereo"
|
||||
;;
|
||||
*)
|
||||
target_description="Yeti Stereo Microphone Analog Stereo"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Find the sink ID of the target device
|
||||
target_sink_id=$(wpctl status | awk '/Sinks:/,/Sources:/' | grep "$target_description" | awk '{print $2}' | tr -d '.')
|
||||
|
||||
# If target sink found, switch to it
|
||||
if [ -n "$target_sink_id" ]; then
|
||||
wpctl set-default "$target_sink_id"
|
||||
echo "Switched audio output to: $target_description"
|
||||
else
|
||||
echo "Target device '$target_description' not found."
|
||||
exit 1
|
||||
fi
|
||||
@@ -83,7 +83,7 @@ separator-foreground = ${colors.red}
|
||||
font-0 = JetBrains Mono Nerd Font:size=12;4
|
||||
|
||||
modules-left = xworkspaces xwindow
|
||||
modules-right = picom-status pulseaudio battery memory cpu wlan eth date
|
||||
modules-right = picom-status audio audio_device battery memory cpu wlan eth date
|
||||
|
||||
cursor-click = pointer
|
||||
cursor-scroll = ns-resize
|
||||
@@ -136,7 +136,7 @@ label-mounted = %{F#F0C674}%mountpoint%%{F-} %percentage_used%%
|
||||
label-unmounted = %mountpoint% not mounted
|
||||
label-unmounted-foreground = ${colors.disabled}
|
||||
|
||||
[module/pulseaudio]
|
||||
[module/audio]
|
||||
type = internal/pulseaudio
|
||||
|
||||
format-volume-prefix = " "
|
||||
@@ -149,6 +149,13 @@ label-volume-foreground = ${colors.green}
|
||||
label-muted = muted
|
||||
label-muted-foreground = ${colors.disabled}
|
||||
|
||||
[module/audio_device]
|
||||
type = custom/script
|
||||
exec = ~/.config/polybar/audio_output_status.sh
|
||||
hook-0 = ~/.config/polybar/audio_output_status.sh
|
||||
interval = 0
|
||||
click-left = ~/.config/polybar/audio_output_switch.sh
|
||||
|
||||
[module/xkeyboard]
|
||||
type = internal/xkeyboard
|
||||
blacklist-0 = num lock
|
||||
|
||||
Reference in New Issue
Block a user