Since the Raspberry Pi has a strong appeal to the hobbyist niche then there are undoubtedly lots of cool things that people are doing with their Pis. And what is even cooler is that people love sharing what they have done with others (for tutorials, general help and maybe just for pure bragging rights).
Taking screenshots is an integral part of documenting what you have done on your Pi, but what is the best way to take a screenshot on a Raspberry Pi? I am sure there are probably lots of inventive methods that could be used, but one of the simplest is to use the command line tool “scrot.”
scrot (SCReen shOT) is a simple screen capture utility that is easy to use, yet has some advanced options available. To install scrot on the Raspberry Pi use:
sudo apt-get install scrot
To check that scrot is installed and working as expected, run:
This will print out the scrot version number and exit.
To take a screenshot, you need to have the desktop running on your Pi. Open a terminal window and just execute scrot:
By default screenshots are saved in the current directory using a filename formed by a combination of a time stamp, the screen resolution and the literal “_scrot.” For example:
The problem with command line screen capture tools is that you need to run the command in the terminal window, and that very same terminal window can get in the way of what you really want to capture on the screen. To get around this, scrot has a delay feature. The “-d” option allows you to specify how many seconds the utility should wait before taking the screenshot. During the delay, you can minimize the terminal window and arrange the screen exactly as you want for your screenshot.
Here is how you would run scrot with a 10 second delay:
scrot -d 10
If you look carefully, you will see the minimized terminal window in the task bar, but the important thing is that the main attraction (i.e. the Pi Store) is clearly visible in the screenshot, without any other windows in the way.
scrot allows you to specify a different filename for the screen capture by supplying it as the first parameter, for example:
You can also use special format specifiers in the filename string to ensure that you get a unique filename. For example the specifier “%Y” means the current year. “%m” means the current month as a decimal number (i.e. 1 to 12). “%d” means the day of the month, also as a decimal. So if you put those together, you can insert the date into the file name like this:
The scrot command actually supports all of the format specifiers from the “
strftime()” C programming function. Type “
man strftime” in a terminal to get a full list of all the special characters. In addition to the time and date specifiers, scrot also supports some internal specifiers. These start with “$” rather than “%”. For example, to include the image width and height in the filename, use “$w” in combination with “$h” like this:
Note that the “x” between the “$w” and the “$h” is there as a literal strng and will result in something like this: “1232×992″ where “1232″ is the width, “x” comes from the “x” between “$w” and the “$h”, and “992″ is the height.
The full list of special specifiers are:
- $p – image pixel size
- $w – image width
- $h – image height
- $t – image format
- $$ – a literal ‘$’
- $f – name of the screenshot just captured, for use with “-e” (see below)
scrot can also execute a shell command after the image has been captured. To do this, use the “-e” option followed by the shell command you want to run. For example:
scrot '%Y-%m-%d_$wx$h.png' -e 'mv $f ~/shots/'
This takes a screenshot and saves it into a file with the date and screen resolution (e.g. 2014-07-08_1232x992.png) and then moves the newly created file into a directory called “shots” below the home directory. Notice the “$f” which tells the “move” command the name of the screenshot.
One last interesting option for scrot is the “-u” option. When scrot is called with this flag only the contents of the currently focused window is captured. You can use it with “-d” to give yourself a few seconds to arrange the windows and then capture the active window.
If you have any problems with the examples given above, please feel free to ask questions in the comments section below and we will see if we can help.