#!/bin/sh # Set brightness for DDC/CI enabled monitors export PATH="/var/setuid-wrappers:$PATH" # monitor i2c device device=dev:/dev/i2c-0 # brightness values night=35 transition=45 daytime=60 deref() { eval "echo \$$1" } set_brightness() { sudo ddccontrol $device -r 0x10 -w > /dev/null $1 2>&1 } fade_to() { current=$(sudo ddccontrol $device -r 0x10 2> /dev/null | grep -oP '\+/\K[0-9]+') [ $current -gt $1 ] && step=-1 || step=1 for i in $(seq $current $step $1); do set_brightness $i sleep 1 done } if [ $1 = "period-changed" ]; then if ! (lsmod | grep -q "^i2c_dev"); then sudo modprobe i2c-dev fi fade_to $(deref $3) fi