vitorpy's Dotfiles
at main 53 lines 2.0 kB view raw
1#!/bin/bash 2 3# Get list of available sinks 4sinks=$(pactl list short sinks | awk '{print $2}') 5 6# Get current default sink 7current_sink=$(pactl info | grep "Default Sink:" | cut -d: -f2 | xargs) 8 9# Create menu options for wofi/rofi 10menu_items="" 11while IFS= read -r sink; do 12 # Get sink description 13 description=$(pactl list sinks | grep -A1 "Name: $sink" | grep "Description:" | cut -d: -f2- | xargs) 14 15 # Mark current sink 16 if [ "$sink" = "$current_sink" ]; then 17 menu_items="$menu_items$description\n" 18 else 19 menu_items="$menu_items $description\n" 20 fi 21done <<< "$sinks" 22 23# Show menu using wofi (or rofi if you prefer) 24# Try wofi first, fall back to rofi if not available 25if command -v wofi &> /dev/null; then 26 selected=$(echo -e "$menu_items" | wofi --dmenu --prompt "Select Audio Output" --width 600 --height 400) 27elif command -v rofi &> /dev/null; then 28 selected=$(echo -e "$menu_items" | rofi -dmenu -p "Select Audio Output" -width 600) 29else 30 # Fallback to zenity if neither wofi nor rofi is available 31 selected=$(echo -e "$menu_items" | zenity --list --column="Audio Outputs" --title="Select Audio Output" --width=600 --height=400) 32fi 33 34# If user selected something 35if [ -n "$selected" ]; then 36 # Remove the marker (● or spaces) from the selection 37 selected_clean=$(echo "$selected" | sed 's/^[● ]*//') 38 39 # Find the sink name from description 40 while IFS= read -r sink; do 41 description=$(pactl list sinks | grep -A1 "Name: $sink" | grep "Description:" | cut -d: -f2- | xargs) 42 if [ "$description" = "$selected_clean" ]; then 43 # Set as default sink 44 pactl set-default-sink "$sink" 45 # Move all playing streams to the new sink 46 pactl list short sink-inputs | while read stream; do 47 stream_id=$(echo $stream | awk '{print $1}') 48 pactl move-sink-input "$stream_id" "$sink" 49 done 50 break 51 fi 52 done <<< "$sinks" 53fi