Using my desktop-computer I have the brightness of my monitor turned up full (it is a reasonably sunny room and a reasonably old monitor)
In the evening i turn the brightness down to almost minimum.
Since the values of my monitor settings are set through a menu with 'up' and 'down' entries i thought that setting it could be accomplished in a less 'labour intensive' way.
The goal is to toggle between bright and dim by clicking on an icon on the panel
and in MATE it is easy to make a launcher for a script so let's make that script.
Now the trouble is that my monitor is a bit old and the firmware is therefor either not fully compliant to the standard control protocols or the firmware is just plain buggy.
Mfg id: SAM - Samsung Electric Company Model: SA300/SA350 Product code: 1941 (0x0795) Manufacture year: 2011, Week: 37
Anyway, I want to use ddcutil to do the switching but since my monitor not always seem to understand the commands and sometimes replies a bit confused (1 out of 3 on average) I decided to go bruteforce and keep on repeating the command until the monitor does what it is told to do.
Since it is a toggle, I have to do the same for retreiving the current value from the monitor.
Anyway, this is the script. The only thing you have to do yourself is saving it, making it executable and creating a launcher for it.
#!/bin/bash
# simple brightness toggle (bright/dim) for unwilling monitors and buggy ddcutil
# it keeps on trying until it thinks it succeeds
# no guarantee it will work for you, just try and see
#
# depends on ddcutil (sudo apt get install ddcutil)
#### PRESET VALUES, change it to your hearts desire, 0 is reserved (so don't use that)
max_value=100
min_value=10
#### INIT, comment the 'exec' command when debugging
exec &>/dev/null
declare -i old_value=0
#### GET BRIGHTNESS
while [ $old_value -eq 0 ]
do old_value="$( ddcutil getvcp '10' |tr ":," "\n\n" |grep 'current' |cut -d= -f2 )"
done
#### TOGGLE BRIGHTNESS VALUE
[ $old_value -eq $min_value ] && new_value=$max_value || new_value=$min_value
#### SET NEW BRIGHTNESS
while ! ddcutil setvcp '10' "$new_value" --sleep-multiplier 2.0 --disable-dynamic-sleep
do sleep 0.1
done
Keep in mind though that this script won't work if your monitor returns the wrong values (like off-by-one due to rounding and the like ).