Husk zeropad på hex-verdier
[einar-bin] / screencontrol.sh
1 #!/bin/bash
2 # Script to control and query a connected screen
3 # For infoscreen purposes
4 # Tries to use cec-client and falls back to DPMS
5 # Usage: ./screencontrol.sh [query | on | off]
6
7 export DISPLAY=:0
8 if [ -z "${1}" ]; then
9 set -- "query"
10 fi
11
12 if [ "${1}" == "query" ]; then
13 if status=$(echo "pow 0" | cec-client -s -d 1); then
14 if [[ ${status} =~ (power status: on) ]]; then
15 echo "Screen is on"
16 else
17 echo "Screen is off"
18 fi
19 else
20 if status=$(xset q); then
21 if [[ ${status} =~ (Monitor is Off) ]]; then
22 echo "Screen is off"
23 else
24 echo "Screen is on"
25 fi
26 else
27 echo "Unable to determine status of screen"
28 exit 1
29 fi
30 fi
31 elif [ "${1}" == "on" ]; then
32 if echo "on 0" | cec-client -s -d 1 >/dev/null; then
33 xset s off
34 xset s noblank
35 xset -dpms
36 echo "Screen turned on (CEC)"
37 else
38 if xset dpms force on; then
39 xset s off
40 xset s noblank
41 xset -dpms
42 echo "Screen turned on (DPMS)"
43 else
44 echo "Unable to turn screen on"
45 exit 1
46 fi
47 fi
48 elif [ "${1}" == "off" ]; then
49 if echo "standby 0" | cec-client -s -d 1 >/dev/null; then
50 echo "Screen turned off (CEC)"
51 else
52 if xset dpms force off; then
53 echo "Screen turned off (DPMS)"
54 else
55 echo "Unable to turn screen off"
56 fi
57 fi
58 else
59 echo "Error: Unknown command"
60 exit 1
61 fi