Hi there,
I read someone mentionning an automatic backlit keyboard (start typing and it automatically switches backlit on). It looks like a no brainer but I didn't find an equivalent on Linux, so I put together a (minimal and ugly) bash script to do just that.
WARNING: it works for me (Thinkpad T480S on Fedora), but it probably won't work on other hardware / distros. Plus it needs to be run as root, so be extra careful!
#!/bin/bash # # CONFIGURATION # # seconds until lights are off off_time=5 # tenths of seconds between keyboard polling polling_time=5 # when shoud we light up keyboard startup_time=20:00 # when do we stop lighting up the keyboard end_time=08:00 # keyboard can be off(0), dimmed(1) or full beams(2) # so you can configure your off and on values on_value=1 off_value=0 # check for root user if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" exit 1 fi # INIT VARIABLES counter=1 light_status=off # polling time in seconds polling_time_s=$(bc <<< "scale=1;$polling_time / 10") # how many counter to wait for the correct(ish) off_time off_time_counter=$(bc <<< "scale=0; (1 / $polling_time_s ) * $off_time") # getting the keyboard (hopefully) keyboard=`xinput list --id-only "Virtual core keyboard" ` keyboard="/dev/input/event${keyboard}" # getting the backlight class (hopefully) backlight=`find /sys/class | grep kbd_backlight` backlight="${backlight}/brightness" while true; do current_time=$(date +%H:%M) if [[ "$current_time" > "$startup_time" ]] || [[ "$current_time" < "$end_time" ]]; then # get input from keyboard POLL=`timeout $polling_time_s cat $keyboard` # keyboard is active, switch lights on if [ "$POLL" ]; then counter=1 if [ "$light_status" == "off" ]; then echo $on_value > $backlight light_status="on" fi # keyboard is inactive... if it stays so for off_time, switch lights off else if [ "$counter" -lt "$off_time_counter" ]; then counter=$((counter + 1)) elif [ "$counter" -eq "$off_time_counter" ]; then echo $off_value > $backlight light_status="off" fi fi else # outside active hours, wait a minute and check again sleep 60 fi done Does anyone knows of a better / less hackish / more official implementation?
[link] [comments]