I have a bash script that I use to adjust my monitor brightness that uses
xrandr --verbose to get the current brightness. It works fine, but using
xrandr is kind of slow on my machine, as you can see here:
[PROMPT REDACTED]$ time xrandr --verbose
# xrandr output omitted for brevity
This outputs lots of information that I don't need, in addition to taking almost a full second. The only line out of the output that I actually need is
Brightness: X. I am currently using this line to get the value from it:
BRIGHTNESS=`xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1`
head is called at the end because I have 2 monitors, so I end up with 2 values, but only need 1, since I am keeping them both at the same brightness.
Since I only need that one line from
xrandr --verbose, I was wondering if there is a way I could "lazily" evaluate it, by doing something like:
xrandroutputting once it reaches that line
- Ignoring the rest of the output from
xrandronce I have read that line
- Something else?
I realize bash may not be the language best suited for this, so I am open to solutions in other languages as well.