Screen timeout/lock script
You don't need to prefix variables with $ inside $(( ... )),
this will work just as well:

idle_secs=$(( minutes * 60 + seconds ))  # Screen timeout in seconds
idle_ms=$(( idle_secs * 1000 ))




In many places you pipe to a grep and then pipe to awk.
Note that awk can perform many of the functions of grep,
and using one process (awk) instead of two (grep + awk) would be more optimal.

Here are some examples. Instead of:


... | egrep '(Width|Height):' | awk '{print $NF}'



This is equivalent:

... | awk '/(Width|Height):/ {print $NF}'


Instead of:


... | grep -m1 dimensions | awk '{print $2}'



This is equivalent:

... | awk '/dimensions/ {print $2; exit}'


And so on, similarly at other places too, you get the idea.



Another common pattern I see at many places:


echo "$br &gt;= 0" | bc -l



That is, using echo to pass a string to a command.
A better way is using here-strings, like this:

bc -l &lt;&lt;&lt; "$br &gt;= 0"




This long line appears at multiple places, sometimes with minor variations:


# If it was interrupted during dimming, reset brightness
xrandr --output $screen --brightness $brightness



It would be better to move this to a function,
for example reset_brightness,
to reduce duplication of logic.