Skip to content

Inhibit Sleep on a Linux Desktop

Here’s a quick script to keep your desktop awake when it’s doing something that requires it to not sleep (network backup, etc.):

$ cat /usr/local/bin/nosleep

export DISPLAY=:0.0
while true; do xdotool mousemove_relative --sync --  1  1 ; xdotool mousemove_relative --sync -- -1 -1; sleep 60; done

To use it, create a new terminal and type ‘nosleep’. When you’re done with whatever, just kill it.

It works by moving the mouse cursor back and forth by one pixel, instantly, every minute. If you want to see it actually working, try changing ‘1’ to ‘100’ and ‘-1’ to ‘-100’ and put ‘sleep 2;’ between the two xdotool statements. You’ll see the cursor jump down and right, then back to where it started.

Note that apps like CD burners and software update programs often already have their own sleep inhibitors built in.