Digital Cabin

log whoami uses code feeds

bright - control your monitor brightness from terminal


Hey hey, just a small tip today! Ever wanted to control brightness on your PC monitors like backlight on your laptop? Well you can! Many modern (and not so modern, really) monitors actually have a communication link with a PC. Even VGA later in life got I²C bus in it.

Anyways, to cut to the chase. DDC/CI is the thing that lets you talk to the monitor, and on Linux you want ddcutil to actually do the needful. I am sure other OSes have something similar, but since I don’t use them, you’ll have to dust out a search engine, or talk with proprietary number matrices known as LLMs. (The author does not condone the latter.) Now that you know what to search for, it should be easy!

For myself I made a little shell script called bright that I use to query and change the brightness using ddcutil:

#!/bin/sh -e

if [ $# -ne 1 ]; then
    ddcutil --bus=7 getvcp 10 | sed -E 's/.+current value =\s+(.+),.+/\1/'
    exit
fi

[ "$1" = "-h" ] && \
{
    echo Usage: "$(basename "$0")" "[-h|[+|-]brightness 0-100]" >&2
    echo "       Calling with no arguments returns current brightness" >&2
    echo "       Calling without a sign sets the brightness to specified value" >&2
    echo "       Otherwise adjusts current brightness by specified value" >&2
    exit 1
}

rel=$(echo "$1" | head -c 1)
num=$(echo "$1" | tail -c +2)
if [ "$rel" != "+" ] && [ "$rel" != "-" ]; then
    ddcutil --bus=7 setvcp 10 "$1" &
    ddcutil --bus=9 setvcp 10 "$1" &
else
    ddcutil --bus=7 setvcp 10 "$rel" "$num" &
    ddcutil --bus=9 setvcp 10 "$rel" "$num" &
fi

wait

The script allows me to query, set or change the brightness from terminal, which I also mapped to keys in my i3 config:

...
bindsym $mod+F11 exec ~/scripts/bright -15
bindsym $mod+F12 exec ~/scripts/bright +15
...

It can take a second or two to actually change the brightness on my screens, and ddcutil is blocking till the commands are finished, so I spawn them in background and wait on them.

In my case I just hardcoded the bus addresses of my 2 monitors, you can replace them with your own that you discovered with ddcutil detect and then figured out the correct VCP with ddcutil capabilities --bus=$I2C_addr. You can control more than brightness with this, but it depends on what your specific monitor exposes. This is enough for my usecase, for now.

That’s it for today! Have fun with your display(s).


P.S. Once again I am not posting much, but this time I am slowly cooking few things. So unless something drastic happens, expect more posts soon!


[Valid Atom 1.0] More…