/
activate-keyboard-backlighting.sh
executable file
·64 lines (35 loc) · 1.18 KB
/
activate-keyboard-backlighting.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/sh
usage="Usage: $(basename $0) [-h|--help] [level]: activates the keyboard backlighting; for level 0: 0%, i.e. switched off; for level 1: 50%; for level 2 (the default, if none is specified): 100%.
Note that at least with some Thinkpad (e.g. T470), hitting Fn-Spacebar (unless Fn and Ctrl are swapped) allows to cycle through backlighting levels.
"
if [ ! $(id -u) -eq 0 ]; then
echo " Error, you must be root." 1>&2
exit 5
fi
ctrl_tool=$(which brightnessctl 2>/dev/null)
if [ ! -x "${ctrl_tool}" ]; then
echo " Error, 'brightnessctl' tool not available. One may use: 'pacman -Sy brightnessctl'." 1>&2
exit 10
fi
device="tpacpi::kbd_backlight"
# If ever wanting to control the screen brightness:
#device="intel_backlight"
device_opt="--device=${device}"
echo "(current brightness level is $(${ctrl_tool} ${device_opt} get))"
level="$1"
if [ "${level}" = "-h" ] || [ "${level}" = "--help" ]; then
echo ${usage}
exit 0
fi
if [ -z "${level}" ]; then
level=2
fi
echo "Setting brightness level to ${level}."
${ctrl_tool} ${device_opt} set ${level}
res=$?
if [ $res -eq 0 ]; then
echo "(success)"
else
echo "Error, setting failed (code: $res)." 1>&2
exit 15
fi