How to Automatically Capture Screenshots on Linux

This guide walks you through creating a Bash script to automatically take screenshots on Linux and save them to a specific directory on your computer.

The script uses `scrot`, a straightforward and efficient command-line tool for taking screenshots in Linux.

To install it, open your terminal and enter:

  • For Ubuntu/Debian:

    sudo apt update
    sudo apt install scrot

  • For Fedora/RHEL:

    sudo dnf install scrot

  • For Arch Linux:

    sudo pacman -S scrot

After installation, confirm it works by running:

scrot --version

Now, let’s create a Bash script to automate the screenshot process.

The script will capture 100 screenshots in succession, with a 5-minute (300-second) interval between each one, saving them in a directory called `temp2` inside your `Pictures` folder.

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

The first line, `#!/bin/bash`, specifies that the script is written in Bash.

The second line, `for i in {1..100}`, starts a loop that runs 100 times.

The `scrot` command is then executed with the following parameters:

  • `-d 300`: Delays the next screenshot by 300 seconds (5 minutes).
  • `'Taken_on-%d-%m-%Y-%H:%M:%S.png'`: Sets the filename format, including the date and time (day, month, year, hour, minute, second) to keep track of when each screenshot was taken.
  • `-e`: Defines the command to execute after saving the screenshot.
  • `mv $f ~/Pictures/temp2/`: Moves the saved file to the `temp2` directory in the `Pictures` folder, keeping everything neatly organized.

You can use any text editor to write and save the script. For example:

nano ~/screenshot_auto.sh

Paste the script code, save the file, and exit the editor. Then, make the script executable:

chmod +x ~/screenshot_auto.sh

Before running the script for the first time, make sure the target directory exists:

mkdir -p ~/Pictures/temp2

You’re now ready to execute the script.

Run it from the terminal with:

./screenshot_auto.sh

The script will start capturing the screen every 5 minutes and save the images to the specified folder.

After capturing 100 screenshots, the script will stop. If you want to take more screenshots, simply adjust the loop in the script.

To stop the script early while it’s running, press `Ctrl + C` in the terminal.

Once the script is finished, you’ll find files named like:

Taken_on-23-11-2024-10:15:30.png
Taken_on-23-11-2024-10:20:30.png
...

All saved in the directory `~/Pictures/temp2/`.

Note: If you want the script to run automatically at startup, you can modify your application startup configuration file.

nano ~/.bashrc

Then, add this line to the end of the file:

~/screenshot_auto.sh &

With this setup, you don’t need to manually run the script. It will automatically start every time you log in to your system.

That’s all there is to it!

Every metric space is Hausdorff. If a topological space is not Hausdorff, it cannot be derived from a metric.

Note: A topological space is Hausdorff if, for any two distinct points, there exist disjoint open neighborhoods that separate them.

 
 

Please feel free to point out any errors or typos, or share suggestions to improve these notes. English isn't my first language, so if you notice any mistakes, let me know, and I'll be sure to fix them.

FacebookTwitterLinkedinLinkedin
knowledge base