Automatic turn off keyboard backlight when idle

Hi,

I made a small script to automatically turn off keyboard backlight when idle, resume when there’s input, it works with my Asus Zenbook UX3405CA laptop, and I believe it works with others with minor modifiaction to the script to your specification.

#!/bin/bash

# brightnessctl and swayidle are required !!!


# Configuration
KEYBOARD_BACKLIGHT_DEVICE="asus::kbd_backlight"
IDLE_TIMEOUT=5 # in seconds

# Start swayidle to monitor for inactivity
swayidle \
  timeout $IDLE_TIMEOUT "brightnessctl --device='$KEYBOARD_BACKLIGHT_DEVICE' set 0" \
  resume "brightnessctl --device='$KEYBOARD_BACKLIGHT_DEVICE' set 1"

Don’t forget to chmod your script !!!

Just add the script to Autostart –> Login script and restart your system.

Sadly it doesn’t work when watching Youtube on Chrome but I believe it is related to the inhibit systemd function because while I’m on Youtube regardless of whether I’m playing or not the sleep function will not be triggered.

However you could minizie the browser if you aren’t watching it and just listening to it, the script will work.

Cheers!