-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatogglesh
More file actions
executable file
·61 lines (52 loc) · 2.33 KB
/
Copy pathpatogglesh
File metadata and controls
executable file
·61 lines (52 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# paswitch 2011-02-02 by Ng Oon-Ee <ngoonee.talk@gmail.com>
# array of sound cards
cards=($(pacmd list-sinks | sed 's|*||' | awk '$1 == "index:" {print $2}'))
totalsc=${#cards[@]}
if [ $totalsc -le 1 ]; then # Check whether there are actually multiple cards available
notify-send -u critical -t 5000 "Nothing to switch, system only has one sound card."
exit
fi
# $scindex: The Pulseaudio index of the current default sound card
scindex=$(pacmd list-sinks | awk '$1 == "*" && $2 == "index:" {print $3}')
PICKNEXTCARD=1 # Is true when the previous card is default
while [ ${#cards[@]} -gt 0 ]
do
for i in ${!cards[@]}; do
CARD=${cards[$i]}
if [ $PICKNEXTCARD = 1 ]; then
# $nextsc: The pulseaudio index of the next sound card (to be switched to)
nextsc=$CARD
PICKNEXTCARD=0
fi
if [ $CARD = $scindex ]; then # Choose the next card as default
PICKNEXTCARD=1
fi
done
pacmd set-default-sink $nextsc # switch default sound card to next
# ensure that switch was successful, and try again if not
currsc=$(pacmd list-sinks | awk '$1 == "*" && $2 == "index:" {print $3}')
if [ $currsc = $scindex ]; then
unset cards[$i]
else
break
fi
done
# $inputs: A list of currently playing inputs
inputs=$(pacmd list-sink-inputs | awk '$1 == "index:" {print $2}')
for INPUT in $inputs; do # Move all current inputs to the new default sound card
pacmd move-sink-input $INPUT $nextsc
done
# $nextscdec: The device.description of the new default sound card
# NOTE: This is the most likely thing to break in future, the awk lines may need playing around with
#nextscdesc=$(pacmd list-sinks | awk '$1 == "device.description" {print substr($0,5+length($1 $2))}' \
# | sed 's|"||g' | awk -F"," 'NR==v1{print$0}' v1=$((nextind+1)))
#notify-send "Default sound-card changed to $nextscdesc"
#dbus-send --session --type=method_call --reply-timeout=10000 \
# --dest=org.freedesktop.Notifications /org/freedesktop/Notifications \
# org.freedesktop.Notifications.Notify string:"paswitch" uint32:1 \
# string:$icon_name string:"Default sound card is now" string:"$nextscdesc" \
# array:string:"" dict:string:string:"","" int32:3000
# Below text was from original author and remains unaltered
# CC BY - creative commons
# Thanks God for help :) and guys lhunath, geirha, Tramp and others from irc #bash on freenode.net