Created
April 11, 2023 13:30
-
-
Save joshbmarshall/30da334af63e8859c52f92e72068b246 to your computer and use it in GitHub Desktop.
Automatic keyboard backlight on/off on Thinkpad bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
startup_time="20:00" | |
end_time="08:00" | |
inactivity_time=10000 | |
polling_interval=0.5 | |
device=tpacpi::kbd_backlight | |
on_value=1 | |
off_value=0 | |
# Initial state | |
brightnessctl -d $device s $off_value | |
light_status=off | |
while true; do | |
idle=`xprintidle` | |
if [ "$light_status" == "off" ]; then | |
if [ $idle -lt $inactivity_time ]; then | |
current_time_epoch=$(date +%s) | |
startup_time_epoch=$(date +%s -d "today $startup_time") | |
end_time_epoch=$(date +%s -d "today $end_time") | |
if [ $current_time_epoch -ge $startup_time_epoch ] || [ $current_time_epoch -le $end_time_epoch ]; then | |
brightnessctl -d $device s $on_value | |
light_status=on | |
echo "Lights on" | |
else | |
sleep 10 | |
fi | |
fi | |
fi | |
if [ "$light_status" == "on" ]; then | |
if [ $idle -gt $inactivity_time ]; then | |
brightnessctl -d $device s $off_value | |
light_status=off | |
echo "Lights off" | |
fi | |
fi | |
sleep $polling_interval | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment