summaryrefslogtreecommitdiff
path: root/idle.sh
blob: 138764f7ef2202d3d12ab8dc77794ff9991c62cc (plain)
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
#!/usr/bin/bash

mutev=true # stop volume/sound(mute) - comment or un-comment
pmusic=true # stop/start music from playing - command or un-comment
IDLETIME=1800000
IDLEBACKTIME=100


while true; do
    if [[ "$(systemctl is-system-running)" == "running" || "$(systemctl is-system-running)" == "degraded" ]]; then
        if [[ "$(xprintidle)" -gt $IDLETIME && ! -f /tmp/lock/idle.lock ]]; then  # Changed from 600000 (10 minutes) to 3600000 (1 hour)
            printf "User is idle(afk) in %s\n", "$(date)"
            sudo /sbin/touch /tmp/lock/idle.lock
            #if [ $mutev ]; then
            #    soundlevel=$(awk -F"[][]" '/Left:/ { print $2 }' <(amixer sget Master))
            #    amixer set Master 0%
            #fi
            if [ $mutev ] && [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: no" ]]; then
                amixer set Master mute
            elif [ $mutev ] && [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
                notify-send "Warning: Volume is already muted"
            elif [ $mutev ] && [[ ! $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: no" ]] && [[ ! $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
                notify-send -u critical "Unable to get volume(sound) status: $(pactl get-sink-mute @DEFAULT_SINK@)"
            fi
            script -c "$HOME/scripts/update.sh" $HOME/scripts/logs/auto-updater.log -a --force
            if [ $pmusic ] && [[ $(NekoMC --status) == "Playing" ]]; then
                m=true
            fi
            if [ $pmusic ] && [ $m ]; then
                NekoMC --pause &
            fi
            #killall picom; bspcomp & # paused in freezeapp and unfreezeapp
            # Disable mouse just in case accidental awake for high DPI rate mouse
            xinput --disable 12
            freezeapp &
            continue
        elif [[ "$(xprintidle)" -le $IDLEBACKTIME && -f /tmp/lock/idle.lock ]]; then
            printf "User is back from idle(afk) in %s\n", "$(date)"
            #if [ $mutev ] && [ $soundlevel ]; then
            #    amixer set Master $soundlevel
            #    unset $soundlevel
            #elif [ $mutev ] && [ ! $soundlevel ]; then
            #    notify-send "ERROR: \$soundlevel is not set, unknown sound level..."
            #fi
            # Re-enable mouse
            xinput --enable 12
            if [ $mutev ] && [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
                amixer set Master unmute
            elif [ $mutev ] && [[ $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: no" ]]; then
                notify-send -u critical "ERROR: Volume(sound) is not muted"
            elif [ $mutev ] && [[ ! $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: no" ]] && [[ ! $(pactl get-sink-mute @DEFAULT_SINK@) == "Mute: yes" ]]; then
                notify-send -u critical "Unable to get volume(sound) status: $(pactl get-sink-mute @DEFAULT_SINK@)"
            fi
            killall update.sh yay
            unfreezeapp &
            if [ $pmusic ] && [ $m ]; then
                NekoMC --play &
                unset m
            fi
            sudo /sbin/rm -f /tmp/lock/idle.lock
            continue
        else
            sleep 1
            continue
        fi
    fi
done