-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_brightness.sh
executable file
·48 lines (35 loc) · 1.15 KB
/
set_brightness.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
#!/bin/bash
# This is a script to change the brightness level
# Takes one argument: the percentage of increase, as whole number
# E.g. brightness.sh -5, brighness.sh 5
# directory of brightness settings
dir="/sys/class/backlight/intel_backlight/"
# brightness file
file="${dir}brightness"
# brightness level
brightness=$(cat "${dir}brightness")
max_brightness=$(cat "${dir}max_brightness")
# percentage of brightness
percentage=$(echo "${brightness}/${max_brightness}" | bc -l)
# new brightness percentage
percentage=$(echo "${percentage} + ($1 / 100)" | bc -l)
# new brightness, decimals cut off
brightness=$(echo "${max_brightness} * ${percentage}" | bc | cut -d'.' -f1)
# cut off new brightness if too big
if [ ${brightness} -gt "${max_brightness}" ]
then
brightness=${max_brightness}
fi
# cut off new brightness if less than zero
if [ ${brightness} -lt "0" ]
then
brightness=0
fi
# sometimes permissions change over time (update/reboot I think)
# my sudo has no password so I can use this
sudo chmod 666 ${dir}brightness
# actual changing the brightness
echo "${brightness}" > ${file}
# inform `i3blocks` about the change
pkill -RTMIN+10 i3blocks
exit 0