How to Automatically Take Screenshots In Ubuntu At Regular Interval

It is easy to take a screenshot in Ubuntu. You can use the “Print Screen” button on your keyboard (if it comes with one), the default screenshot tool or any other third-party software. What if you want the system to take a screenshot automatically at a regular interval, say every 5 seconds? The above tools won’t be able to do the job. Here is a quick way you can take screenshots in Ubuntu at regular interval.

Installing scrot

The tool that we are going to use is scrot. Scrot is a command line utility that allows you to capture screenshot from the terminal.

Scrot is in the Ubuntu repository, so you can simply install from Ubuntu Software Center, or in the terminal:

sudo apt-get install scrot

Capturing screenshots at regular interval

To use Scrot to capture screenshots automatically at regular interval, all you need to do is to run the following command in the terminal:

while true; do scrot -d int  'filename.jpg|png' -e 'mv $f /file/path/to/store/screenshots'; done

Here are a few parameters that you need to change:

  • int – the number of seconds before each screenshot is taken
  • filename – the filename of the screenshot. You can use variables like %Y, %m, %d, %H, %M, %S $w, $h to denote the year, month, day, hour, minute, seconds, width and height respectively.
  • jpg|png – take the screenshot in either jpg or png format. Include only one, but not both.
  • file/path/to/store/screenshots – the location where you want to move the screenshots to

For example, if you want it to take a screenshot at every 5 seconds and save it to the Pictures folder. This is the command to use:

while true; do scrot -d 5 '%Y-%m-%d-%H:%M:%S.png' -e 'mv $f ~/Pictures/'; done

Note: Press Ctrl + z to end the process.

Note: Depending on your monitor size and amount of resources in your computer, Scrot will take about 1 -2 second to complete each cycle. This means that when you set the interval at 5 seconds, the screenshot will only be taken at 6 -7 seconds. You might want to adjust the interval to compensate for this lag

After running it for 1 minute, this is what I found in my Pictures folder.

screenshots in Ubuntu Saved to Ppictures folder

The above command will run the process forever until you stop it manually. If you want to get it to run for a certain count, say 100 loops, you can use the command below:

for i in {1..100}; do scrot -d 5 '%Y-%m-%d-%H:%M:%S.png' -e 'mv $f ~/Pictures/'; done

This will take 100 screenshots at an interval of 5 seconds.

Putting it in script

It is barely useful if you need to type the command everytime you want to run the process. The best way is to turn it into a script where you can run it anytime, everytime.

Open a text editor and paste the following commands:

#!/bin/bash
 
for i in {1..100}
do
   scrot -d 5 '%Y-%m-%d-%H:%M:%S.png' -e 'mv $f ~/Pictures/';
done

Save the file as auto-screenshot.sh in your Home folder. Grant it executable permission:

chmod +x ~/auto-screenshot.sh

Now you can run the process by using the command in the terminal:

./auto-screenshot.sh

Automating the screen capturing process

If you want to schedule the screen capturing process to run at a certain time everyday, the fastest way is to set a cronjob. If you prefer a more graphical approach, Gnome Schedule is one good app that you can use, provided you are using the Gnome desktop.

For further automation, you can even use CuttleFish to trigger the screen capturing process when a condition is met.

What other ways do you use to automate screen capturing at regular interval?

Image credit: Print Screen by BigStockPhoto

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Damien Oh

Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.