I needed something to power up display to 100% while on AC Power and to automatically dim it to 50% while on battery. Unfortunately this can’t be configured in UI in system settings. Hey, Apple, you haven’t something like this either.
I did some research and script triggered by udev should do the trick.
1. Install brightnessctl
sudo apt install brightnessctl2. Create the script
Create a set-brightness.sh file
sudo nano /usr/local/bin/set-brightness.shCopy and Paste this (adapt to your needs)
#!/bin/bash
# Check if device is powered by AC Powers
AC_STATUS=$(cat /sys/class/power_supply/AC*/online)
if [[ "$AC_STATUS" == "1" ]]; then
brightnessctl set 100%
else
brightnessctl set 50%
fi
Make the script executable
sudo chmod +x /usr/local/bin/set-brightness.shTest the script by running (set your brightness manually to 20% or 80% before to see if the script actually changes the brightness)
sh /usr/local/bin/set-brightness.sh3. Configure udev – adding a rule
create a 99-brightness.rules file
sudo nano /etc/udev/rules.d/99-brightness.rulesCopy and Paste:
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/set-brightness.sh"
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/set-brightness.sh"4. Reload udev-rules
sudo udevadm control --reload-rules
sudo udevadm triggerOptionally restart udev
sudo systemctl restart systemd-udevd![[ˈmʊʁksn̩]](https://mrxn.at/wp-content/uploads/2025/04/IMG_7766.jpeg.pagespeed.ce.NhhWe0WnxW.jpg)



Schreibe einen Kommentar