How to use the command scrot (with examples)
- Linux
- December 25, 2023
Scrot is a screen capture utility that allows users to capture screenshots of their desktop or specific windows. It provides various options to customize the screenshots, such as selecting a specific region or window, adding a countdown before capturing, and saving the files with custom filenames.
Use case 1: Capture a screenshot and save it to the current directory with the current date as the filename
Code:
scrot
Motivation: This use case is useful when you quickly want to capture a screenshot of your desktop without specifying a custom filename. It automatically saves the screenshot with the current date and time as the filename, making it easy to reference later.
Explanation: The command scrot
captures a screenshot of the entire desktop and saves it to the current directory. By default, it uses the current date and time as the filename in the format YYYY-MM-DD_HH:MM:SS.png
.
Example output: A screenshot of the desktop is saved in the current directory with a filename like 2022-01-01_12:30:00.png
.
Use case 2: Capture a screenshot and save it as capture.png
Code:
scrot capture.png
Motivation: Sometimes, you may need to capture a screenshot and save it with a specific filename. This use case allows you to specify a custom filename for the screenshot.
Explanation: The command scrot capture.png
captures a screenshot of the entire desktop and saves it with the filename capture.png
. The .png
file extension ensures that the screenshot is saved in the PNG image format.
Example output: A screenshot of the desktop is saved in the current directory with the filename capture.png
.
Use case 3: Capture a screenshot interactively
Code:
scrot --select
Motivation: This use case is useful when you want to capture a specific region of your desktop instead of the entire screen. It allows you to select the desired region using your mouse.
Explanation: The argument --select
enables interactive mode, which means you can click and drag to select the region you want to capture. After you release the mouse button, the selected region is captured and saved as a screenshot.
Example output: A screenshot of the selected region is saved in the current directory with a filename like 2022-01-01_12:30:00.png
.
Use case 4: Capture a screenshot interactively without exiting on keyboard input, press ESC
to exit
Code:
scrot --select --ignorekeyboard
Motivation: When capturing a screenshot interactively, by default, the process exits as soon as you press any key on the keyboard. This use case allows you to ignore keyboard input and keep the selection interface open until you press ESC
to exit.
Explanation: The argument --ignorekeyboard
prevents the program from exiting on keyboard input. This allows you to take your time selecting the desired region without worrying about accidentally closing the selection interface.
Example output: A screenshot of the selected region is saved in the current directory with a filename like 2022-01-01_12:30:00.png
.
Use case 5: Capture a screenshot interactively delimiting the region with a colored line
Code:
scrot --select --line color=x11_color|rgb_color
Motivation: This use case is helpful when you want to visually distinguish the selected region from the rest of the screen by adding a colored line around the borders of the region.
Explanation: The argument --line
enables the display of a colored line around the selected region. You can specify the color of the line using either an X11 color name (e.g., red
, blue
) or an RGB color in the format #RRGGBB
.
Example output: The selected region is highlighted with a colored line (e.g., red) on the screen during the selection process. A screenshot of the selected region is saved in the current directory with a filename like 2022-01-01_12:30:00.png
.
Use case 6: Capture a screenshot from the currently focused window
Code:
scrot --focused
Motivation: When you only need to capture the contents of the currently focused window and not the entire desktop, this use case comes in handy. It allows you to capture the focused window quickly.
Explanation: The argument --focused
captures the contents of the currently focused window and saves it as a screenshot. This is useful when you have multiple windows open and want to capture a specific window’s content without capturing the entire screen.
Example output: A screenshot of the currently focused window is saved in the current directory with a filename like 2022-01-01_12:30:00.png
.
Use case 7: Display a countdown of 10 seconds before taking a screenshot
Code:
scrot --count --delay 10
Motivation: Sometimes, you may need a few seconds to set up the desktop or go to a specific window before capturing the screenshot. This use case adds a countdown before taking the screenshot, allowing you to prepare.
Explanation: The argument --count
enables the countdown mode. By specifying --delay 10
, the countdown will be set to 10 seconds. The timer is displayed on the screen, giving you time to set up the desired state before capturing the screenshot.
Example output: A countdown timer is displayed on the screen, starting from 10 seconds and counting down to 0. After the countdown finishes, a screenshot of the desktop is saved in the current directory with a filename like 2022-01-01_12:30:00.png
.
Conclusion:
Scrot is a versatile screen capture utility that provides various options to customize the screenshots based on your needs. Whether you want to capture the entire desktop, a specific region or window, add a countdown timer, or save the screenshots with custom filenames, Scrot has got you covered. Experiment with the different use cases and explore the additional options provided by Scrot to enhance your screenshot capturing experience.