-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch-sound.bash
executable file
·37 lines (36 loc) · 1.16 KB
/
switch-sound.bash
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
#!/bin/bash
while getopts "hsp" opt; do
case "$opt" in
h)
echo "Usage: $0 [-c] [-f] [-h]"
echo "-s for speakers"
echo "-p for headphones"
echo "-h for help"
echo " No option switches from one to the other."
exit 0
;;
s)
echo "Switching to speakers"
pactl set-sink-port 0 analog-output-lineout
pactl set-sink-volume 0 69%
;;
p)
echo "Switching to headphones!"
pactl set-sink-port 0 analog-output-headphones
pactl set-sink-volume 0 50%
;;
*)
if pactl list sinks | grep -i "Active Port" | grep -i "headphones" >/dev/null; then
# We have headphones, therefore we want to swtich to speakers.
echo "Swtichinmg from headphones to line out."
pactl set-sink-port 0 analog-output-lineout
pactl set-sink-volume 0 69%
else
# We have speakers, therefore we want to swtich to headphone.
echo "Swtichinmg from line out to headphones."
pactl set-sink-port 0 analog-output-headphones
pactl set-sink-volume 0 30%
fi
;;
esac
done