Sometimes it’s painful to stare for few hours at a too bright monitor, especially at night.

Luckily this can be easily solved by setting the output brightness with XRandR, the problem is that it’s not so handy as the command to type is quite long, for example:

$ xrandr --output DVI-I-1 --brightness 0.9

In this case the DVI output connected to my monitor will be filtered resulting in a lower brightness of -0.10 from the default 1.00.

Notice that this is a software modification as man xrandr explains, if you’re using a laptop or a monitor that has hardware support to change the brightness you should check xbacklight.

You can try the command out, but first run xrandr and modify the line to fits your output:

$ xrandr

DisplayPort-0 disconnected primary (normal left inverted right x axis y axis)
HDMI-A-0 disconnected (normal left inverted right x axis y axis)
DVI-D-0 disconnected (normal left inverted right x axis y axis)
DVI-I-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 298mm

As you can see it works fine but as I said it’s quite a pain to execute and open a terminal every time you need to lower/raise the brightness would be extremely boring.

So I came up with a short script that can be used as a shortcut:

xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')+0.1" | bc)

This basically extract the current brightness value and then add/subtract a decimal value that results in a lower or higher brightness.

On i3 I use this with the KeyPad + and – keys, like this:

bindsym $mod+Shift+KP_Add exec xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')+0.1" | bc) 
bindsym $mod+Shift+KP_Subtract exec xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')-0.1" | bc)


If you’re using more than one monitor you’ll first need to grep the specific output information and then grep the brightness from those info, like this:

$ xrandr --verbose |grep DVI-I-1 -A 5

DVI-I-1 connected 1920x1080+0+0 (0x5a) normal (normal left inverted right x axis y axis) 531mm x 298mm
 Identifier: 0x58
 Timestamp: 38302793
 Subpixel: horizontal rgb
 Gamma: 1.0:1.0:1.0
 Brightness: 0.70

As you can see with this command you can grep where the DVI-I-1 output is and plus 5 lines (the “-A 5” option), the fifth line contains the brightness value specific to that output (if it doesn’t increase the amount of lines printed until brightness is there), at this point you can grep that one as showed above, some examples:

xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep DVI-I-1 -A 5 |grep Brightness |grep -o '[0-9].*')-0.1" | bc)

xrandr --output HDMI-A-0 --brightness $(echo "$(xrandr --verbose |grep HDMI-A-0 -A 5 |grep Brightness |grep -o '[0-9].*')-0.1" | bc)

xrandr --output DisplayPort-0 --brightness $(echo "$(xrandr --verbose |grep DisplayPort-0 -A 5 |grep Brightness |grep -o '[0-9].*')-0.1" | bc)