I'm using Linux Mint, and I run the below service with system start up to0 take automatically screenshots, but I need it to stop taking screenshots if the computer is idle, and run again when it is active(for example, the mouse is moved). How can this be accomplished?

while true; do
  scrot -d 70 '%Y-%m-%d-%H:%M:%S.jpg' -e 'mv $f 

1 Answer 1


Use xprintidle:

xprintidle is a utility that queries the X server for the user's idle time and prints it to stdout (in milliseconds).

while :; do
    [ $(xprintidle) -lt 10000 ] && echo do_something
    sleep 3;

This will echo do_something every 3 seconds if last keyboard or mouse activity was less than 10 seconds ago.

You might need to install it, e.g.:

sudo apt install xprintidle

or build it yourself from source.

  • should i replace do_something with my service ? sorry because i'm new in Linux
    – MoSalah
    Mar 25, 2019 at 16:48
  • Put your command after &&
    – pLumo
    Mar 25, 2019 at 17:10

Not the answer you're looking for? Browse other questions tagged .