Skip to content

Instantly share code, notes, and snippets.

@semeion
Created May 17, 2019 18:47
Show Gist options
  • Save semeion/bdbef91008ed3d5a22c9e284c2d568cb to your computer and use it in GitHub Desktop.
Save semeion/bdbef91008ed3d5a22c9e284c2d568cb to your computer and use it in GitHub Desktop.
udev script for handling power management
SUBSYSTEM=="power_supply", ACTION=="change", RUN+="/etc/scripts/battery.sh"
#!/bin/bash
AC=$(cat /sys/class/power_supply/AC/online)
# 2 hour DPMS timeout on AC, 10 minute timeout on battery
[ $AC -eq 1 ] && DPMS=7200 || DPMS=600
for D in /tmp/.X11-unix/X*; do
[ -S "$D" ] && sudo -u $(stat -c %U $D) DISPLAY=:${D##*X} /usr/bin/xset dpms $DPMS $DPMS $DPMS
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment