Script to prevent screen blanking using "mouse move" doesn't work

You can use

xset -dpms; xset s off

to stop the screen from going black.

To enable this again use

xset +dpms; xset s on

So -dpms disables the the power energy saving features, which can turn off the whole monitor and s off turns off the screen saver feature of the X server.

This does not work with the xscreensaver, which was mentioned in the comments.


You have a couple of issues, first, you will need 2 iterations of top each time, see my answer here and the bug report here.

The other problem is that bash does not do floating point, so if your CPU usage is something like 6.2, the .2 will break the script. Bash is simply not designed for 'complex' arithmetic operations. One way around this would be to move the >5 check inside your awk command:

#!/usr/bin/env bash

sleep_period=60s 

while true; do
    until top -bn 2 -d 0.01 | sed -nrs '8p' | awk '{if($9>5){exit 1}else{exit 0}}'; do
      xdotool mousemove 0 100
      xdotool mousemove 0 50
      sleep ${sleep_period}
    done
   sleep ${sleep_period}
done

Tags:

Bash Script