vitorpy's Dotfiles
at main 53 lines 2.1 kB view raw
1#!/bin/bash 2 3# Get list of available sources 4sources=$(pactl list short sources | grep -v ".monitor" | awk '{print $2}') 5 6# Get current default source 7current_source=$(pactl info | grep "Default Source:" | cut -d: -f2 | xargs) 8 9# Create menu options for wofi/rofi 10menu_items="" 11while IFS= read -r source; do 12 # Get source description 13 description=$(pactl list sources | grep -A1 "Name: $source" | grep "Description:" | cut -d: -f2- | xargs) 14 15 # Mark current source 16 if [ "$source" = "$current_source" ]; then 17 menu_items="$menu_items$description\n" 18 else 19 menu_items="$menu_items $description\n" 20 fi 21done <<< "$sources" 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 Input" --width 600 --height 400) 27elif command -v rofi &> /dev/null; then 28 selected=$(echo -e "$menu_items" | rofi -dmenu -p "Select Audio Input" -width 600) 29else 30 # Fallback to zenity if neither wofi nor rofi is available 31 selected=$(echo -e "$menu_items" | zenity --list --column="Audio Inputs" --title="Select Audio Input" --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 source name from description 40 while IFS= read -r source; do 41 description=$(pactl list sources | grep -A1 "Name: $source" | grep "Description:" | cut -d: -f2- | xargs) 42 if [ "$description" = "$selected_clean" ]; then 43 # Set as default source 44 pactl set-default-source "$source" 45 # Move all recording streams to the new source 46 pactl list short source-outputs | while read stream; do 47 stream_id=$(echo $stream | awk '{print $1}') 48 pactl move-source-output "$stream_id" "$source" 49 done 50 break 51 fi 52 done <<< "$sources" 53fi