-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_off
executable file
·63 lines (53 loc) · 1.95 KB
/
monitor_off
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
#!/bin/bash
##############################################################
# Copyright (C) 2009 Vinicius (Arch Linux Forums) #
# https://bbs.archlinux.org/viewtopic.php?pid=506374#p506374 #
# Copyright (C) 2018 BrainwreckedTech #
# Fixed greps, added verbiage, added test capability #
##############################################################
# Check if X is running or not, turn off monitor, #
# wait for a key press and turn it on again. #
##############################################################
grep_result_file=$PWD'/x_running'
# Check if X is running.
ps -e | grep -e "\bX\b" > $grep_result_file
ps -e | grep -e "\bXorg\b" >> $grep_result_file
ps -e | grep -e "\bXserver\b" >> $grep_result_file
## If you want to check result file, uncomment following lines.
#echo "===== $grep_result_file - begin ====="
#cat $grep_result_file
#echo "===== $grep_result_file - end ====="
if [ ! -s $grep_result_file ] || [[ $(tty) =~ tty ]] || [[ $(tty) =~ vc ]]; then
echo 'Detected X not runnig or you are at console...'
if [ $UID -ne 0 ]; then
echo 'You need super user privileges to run this script at console.'
echo 'Rerun as super user or start X and run from a terminal.'
exit 0
fi
if [ "${1}" == "test" ]; then
echo "Will use vbetool to turn monitor(s) on and off"
else
turn_off='vbetool dpms off'
turn_on='vbetool dpms on'
fi
else
echo 'Detected X running.'
echo 'Monitor(s) will turn on with the next keyboard or mouse event.'
if [ "${1}" == "test" ]; then
echo "Will use xset to turn monitor(s) on and off"
else
turn_off='xset dpms force off'
fi
fi
if [ "${1}" != "test" ]; then
echo 'Turning off monitor...'
$turn_off
if [ -n "${turn_on}" ]; then
echo 'Waiting for a key press...'
read -n1 -s
echo 'Turning on monitor...'
$turn_on
fi
fi
rm $grep_result_file
echo 'Finished: monitor_off'