-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_suspend.sh
executable file
·47 lines (43 loc) · 1.89 KB
/
auto_suspend.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
#!/bin/bash
: "${AUTORANR_PROFILE=sd}" # change this to the name of the profile you want to use
: "${SUSPEND_TIME:=10}" # set a default timeout of 10 minutes
export DISPLAY=:0
STREAM=false
while true; do
# Check which profile is loaded
PROFILE=$(autorandr --current)
# Check if "sd" profile is loaded
if [[ $PROFILE == $AUTORANR_PROFILE ]]; then
while pgrep steam >/dev/null; do
SECONDS=0
# we want to check if the profile is still loaded, if not, break out of the loop
PROFILE=$(autorandr --current); if [[ $PROFILE != $AUTORANR_PROFILE ]]; then
echo "The $AUTORANR_PROFILE profile is not currently loaded. Will not automatically suspend."
break; fi
# check if a stream is running, if not, start the timer
while tail -2 /home/${USER}/.steam/steam/logs/streaming_log.txt | grep -q '>>> Stopped desktop stream' || STREAM=true; do
if [[ $SECONDS -le 14 && $STREAM == false ]]; then
echo "No Remote Play Stream running, starting $SUSPEND_TIME minute timer to suspend PC"
fi
MINS=$((SECONDS / 60));
if [[ $STREAM == false ]]; then
# reset when resuming from sleep
if [[ $MINS -gt $SUSPEND_TIME ]]; then break; fi
echo "Suspending in $((SUSPEND_TIME - MINS)) minutes"
else
echo "Stream detected, resetting timer..."
STREAM=false; SECONDS=0
fi
# if the timer is up, suspend the PC
if [ "$MINS" -eq "$SUSPEND_TIME" ]; then
echo "Suspending PC..."
sudo systemctl suspend
fi
# we want to check if the profile is still loaded, if not, break out of the loop
PROFILE=$(autorandr --current); if [[ $PROFILE != $AUTORANR_PROFILE ]]; then break; fi; sleep 10
done; sleep 10
done
else
echo "The $AUTORANR_PROFILE profile is not currently loaded. Will not automatically suspend."
fi; sleep 15
done