#!/bin/bash
# Run wpctl in subshell and capture clean output
STATUS=$(wpctl status 2>/dev/null)
# Current default: line with * and number.dot
CURRENT_LINE=$(echo "$STATUS" | grep -F '*' | grep -E '[0-9]+\.' | head -1)
# Extract current ID
CURRENT_ID=$(echo "$CURRENT_LINE" | grep -oP '\d+(?=\.)' | head -1)
# Razer ID
RAZER_ID=$(echo "$STATUS" | grep -i "Razer Leviathan V2" | grep "\[vol:" | grep -oP '\d+(?=\.)' | head -1)
# Douk ID
DOUK_ID=$(echo "$STATUS" | grep -i "Douk Audio K" | grep "\[vol:" | grep -oP '\d+(?=\.)' | head -1)
# Debug
echo "CURRENT_LINE: '$CURRENT_LINE'"
echo "CURRENT_ID: '$CURRENT_ID'"
echo "RAZER_ID: '$RAZER_ID'"
echo "DOUK_ID: '$DOUK_ID'"
# Toggle logic
if [ "$CURRENT_ID" = "$RAZER_ID" ] && [ -n "$DOUK_ID" ]; then
TARGET_ID="$DOUK_ID"
TARGET_NAME="Douk Audio K5 Analog Stereo"
elif [ -n "$RAZER_ID" ]; then
TARGET_ID="$RAZER_ID"
TARGET_NAME="Razer Leviathan V2 Analog Stereo"
else
notify-send "Audio Toggle Error" "Failed to detect devices"
exit 1
fi
echo "Switching to $TARGET_NAME (ID $TARGET_ID)"
wpctl set-default "$TARGET_ID"
sleep 0.5
pactl list short sink-inputs | awk '{print $1}' | while read -r stream; do
pactl move-sink-input "$stream" @DEFAULT_SINK@ 2>/dev/null
done
notify-send "Audio Output" "Switched to $TARGET_NAME"
#!/bin/bash
# Run wpctl in subshell and capture clean output
STATUS=$(wpctl status 2>/dev/null)
# Current default: line with * and number.dot
CURRENT_LINE=$(echo "$STATUS" | grep -F '*' | grep -E '[0-9]+\.' | head -1)
# Extract current ID
CURRENT_ID=$(echo "$CURRENT_LINE" | grep -oP '\d+(?=\.)' | head -1)
# Razer ID
RAZER_ID=$(echo "$STATUS" | grep -i "Razer Leviathan V2" | grep "\[vol:" | grep -oP '\d+(?=\.)' | head -1)
# Douk ID
DOUK_ID=$(echo "$STATUS" | grep -i "Douk Audio K" | grep "\[vol:" | grep -oP '\d+(?=\.)' | head -1)
# Debug
echo "CURRENT_LINE: '$CURRENT_LINE'"
echo "CURRENT_ID: '$CURRENT_ID'"
echo "RAZER_ID: '$RAZER_ID'"
echo "DOUK_ID: '$DOUK_ID'"
# Toggle logic
if [ "$CURRENT_ID" = "$RAZER_ID" ] && [ -n "$DOUK_ID" ]; then
TARGET_ID="$DOUK_ID"
TARGET_NAME="Douk Audio K5 Analog Stereo"
elif [ -n "$RAZER_ID" ]; then
TARGET_ID="$RAZER_ID"
TARGET_NAME="Razer Leviathan V2 Analog Stereo"
else
notify-send "Audio Toggle Error" "Failed to detect devices"
exit 1
fi
echo "Switching to $TARGET_NAME (ID $TARGET_ID)"
wpctl set-default "$TARGET_ID"
sleep 0.5
pactl list short sink-inputs | awk '{print $1}' | while read -r stream; do
pactl move-sink-input "$stream" @DEFAULT_SINK@ 2>/dev/null
done
notify-send "Audio Output" "Switched to $TARGET_NAME"