-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_switch.sh
73 lines (51 loc) · 1.46 KB
/
audio_switch.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Switching to headphones on plug
#
# Sinks may vary depending on your configuration
# Run "pacmd list-sinks" to get sinks and related ports and make changes
# appropriately to the functions
#
# In the case of same port switching the function for changing application
# streams is unecessary
listen_func(){
acpi_listen > /tmp/audio_switch_log
}
set_to_headphones_func(){ # Set sink for headphone plug
pacmd set-default-sink 0
pacmd set-sink-port 0 analog-output-headphones
defaultsink=0
}
set_to_speakers_func(){ # Set sink for headphone unplug
pacmd set-default-sink 1
defaultsink=1
}
set_application_streams(){ # Moving all the sink inputs to the new sink
# $inputs: A list of currently playing inputs
inputs=0
inputs=$(pacmd list-sink-inputs | awk '$1 == "index:" {print $2}')
for application in $inputs
do
pacmd move-sink-input $application $defaultsink
done
}
main_func(){
while [ 1 ]
do
status=$( tail -1 /tmp/audio_switch_log )
if [ "$status" != "$oldstatus" ]
then
if [ "$status" == "jack/headphone HEADPHONE unplug" ]
then
set_to_speakers_func
elif [ "$status" == "jack/headphone HEADPHONE plug" ]
then
set_to_headphones_func
fi
set_application_streams
fi
done
}
echo "garbagestring" > /tmp/audio_switch_log
oldstatus=$(echo "garbagestring")
listen_func &
main_func