-
Notifications
You must be signed in to change notification settings - Fork 0
/
fadePlayPause.sh
64 lines (50 loc) · 1.07 KB
/
fadePlayPause.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
#!/bin/bash
MAX_VOLUME=60
MIN_VOLUME=0
set_volume() {
local VOLUME=$1
amixer sset 'Master' $VOLUME%
}
get_volume() {
amixer get 'Master' | grep -o -m 1 '[0-9]*%' | tr -d '%'
}
fade_out() {
FADE_DURATION=5
local VOLUME=$(get_volume)
local STEP=$((VOLUME / FADE_DURATION))
echo "$VOLUME" > ~/.fadePlayPauseVol
for ((i = 0; i < FADE_DURATION; i++)); do
VOLUME=$((VOLUME - STEP))
set_volume $VOLUME
sleep 0.1
done
set_volume $MIN_VOLUME
}
fade_in() {
if [ -f ~/.fadePlayPauseVol ]; then
MAX_VOLUME=$(cat ~/.fadePlayPauseVol)
fi
local FADE_DURATION=20
local VOLUME=$MIN_VOLUME
local STEP=$((MAX_VOLUME / FADE_DURATION))
for ((i = 0; i < FADE_DURATION; i++)); do
VOLUME=$((VOLUME + STEP))
set_volume $VOLUME
sleep 0.1
done
set_volume $MAX_VOLUME
}
VOLUME_THRESHOLD=10
CURRENT_VOLUME=$(get_volume)
STATUS=$(playerctl status)
if [ "$CURRENT_VOLUME" -lt "$VOLUME_THRESHOLD" ]; then
if [ "$STATUS" = "Paused" ]; then
playerctl --all-players play-pause
fi
fade_in
else
fade_out
if [ "$STATUS" = "Playing" ]; then
playerctl --all-players play-pause
fi
fi