Files

40 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2019-02-05 19:30:40 -08:00
#!/bin/bash
2019-02-06 15:58:28 -08:00
#dim: control display brightness from terminal
#usage: dim x
#where x is an integer for a new display brightness within the [min,max] range of [0,100]
#James B. Ackman 2019-02-06T15:55:20-08:00
2025-05-13 16:45:55 -04:00
#
# Check kernel backlight driver names on your machine: `ls -l /sys/class/backlight/*`
# e.g. acpi_video0 nv_backlight or intel_backlight
# user should be part of the video user group to run this without sudo and a udev rule with correct driver name should be added as `/etc/udev/rules.d/backlight.rules`
#ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
#ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
# Then set following var to your backlight driver name
backlightDriver="intel_backlight"
2019-02-06 15:58:28 -08:00
set -e #exit if an error
percentValue=$1
if [[ $percentValue -lt "0" || $percentValue -gt "100" ]]; then
echo 'value should be in range [0,100]'
exit 1
fi
maxBrightness=$(cat /sys/class/backlight/$backlightDriver/max_brightness)
if [[ $maxBrightness -lt "100" ]]; then
echo 'max_brightness below 100. Edit this script.'
exit 1
fi
newValue=`echo $(( $maxBrightness / 100 * $percentValue ))`
if [[ $newValue -le "0" ]]; then
echo 'value too low'
exit 1
fi
2019-02-06 19:02:54 -08:00
tee /sys/class/backlight/$backlightDriver/brightness <<< $newValue
2019-02-05 19:30:40 -08:00