-
Notifications
You must be signed in to change notification settings - Fork 0
/
micled-toggle
executable file
·55 lines (51 loc) · 1.32 KB
/
micled-toggle
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
#!/usr/bin/env bash
# Turn mic on/off or toggle it based on press delay
# Start -> On
# Press -> On
# Quick release -> Off
# Slow release -> Off
# Start with Off
# Press toggles it to On
# Quick release leaves it as On
# Slow release turns it back Off
timefile=/tmp/micled_timefile
delay=250
amixer_option="name='Capture Switch'"
function toggleCapture {
eval amixer cset "$amixer_option" toggle
}
function onCapture {
eval amixer cset "$amixer_option" on
}
function offCapture {
eval amixer cset "$amixer_option" off
}
function isOn {
eval amixer cget "$amixer_option" | grep -qF 'values=on'
}
case "$1" in
press)
# notify-send Mic Press
# Check if its already on
if ! isOn; then
onCapture;
date +%s%3N > "$timefile"
fi
;;
release)
# If we release after cutoff, toggle again.
if [[ -f $timefile ]]; then
pressStart=$(cat "$timefile")
pressEnd=$(date +%s%3N)
(( difference=pressEnd-pressStart ))
echo "Start $pressStart, End $pressEnd, diff: $difference"
# notify-send Mic "Release: Diff $difference"
if [[ $difference -gt $delay ]]; then
toggleCapture
fi
else
offCapture
fi
rm "$timefile" ||:
;;
esac