Igor Bubelov

About Blog Notes Photos Portfolio

Customizing GNOME Screenshots

Linux ยท Oct 27, 2020

Illustration by Matt Artz

GNOME is the most popular Linux desktop environment and I use it as my daily driver. It comes with reasonable defaults but it can also be customized for your specific workflow. One of the few things I always change in GNOME is how it makes screenshots. In this article, I explain how to use gnome-screenshot and custom shortcuts in order to capture screenshots faster and how to save them to a custom location.

Table of Contents

Taking Screenshots With GUI

Illustration

Opening the Screenshot app is the easiest way to take a screenshot in GNOME and I bet it’s also the most popular choice among casual users and people who don’t take screenshots often. Unfortunately, keeping things simple often means cutting corners here and there which decreases flexibility. Here are the main downsides of using the Screenshot app:

  • It slows you down. You need to open the app and tell it what you need before it can do anything meaningful.
  • It always offers you a predefined file name pattern, something like Screenshot from 2020-10-20 15-49-39.png.

I take screenshots often and I need to do it fast. I also keep them in a special directory which syncs with my other devices and those devices can take screenshots too so I’d like them to agree on some common naming pattern. I prefer ISO 8601, so in my ideal scenario the file names should look like this: 2020-10-24T16:49:23+07:00.png. It would be a nice “bonus feature” but I can live without it.

Taking Screenshots With Default Shortcuts

GNOME developers recognize the inconvenience of opening a separate app every time you need to take a screenshot and they include a set of predefined shortcuts which let you take screenshots much faster:

Illustration

As you can see, there are three common types of screenshots:

  • Whole screen (includes all physical displays!)
  • Active window
  • Any custom area of the screen which you’ll have to specify

Now we’re talking. This way of taking screenshots is faster since you don’t need to open the Screenshot app and you can choose among three different modes of operation which should give you enough flexibility for most of your needs. Although, I still have a couple of issues with this approach:

  • I can’t change the default save path. It saves everything to Pictures but I need it to save all of my screenshots to /home/igor/nextcloud/screenshots.
  • There is no way to change file names, it’s still Screenshot from 2020-10-20 15-49-39.png which I don’t like.

CLI: gnome-screenshot

To see what’s under the hood of that fancy GUI, you can open the Terminal app and type:

man gnome-screenshot
Illustration

That’s a really short and handy manual and it tells us how to take screenshots via the command line. Note that it has the following options:

  • --window for capturing only the current window
  • --area for grabbing a custom area of the screen
  • --file that options allows us to save the resulting screenshot to custom path with custom file name

So, calling gnome-screenshot --window is the equivalent of Alt + PrtScr shortcut and gnome-screenshot --area leads to the same result as Shift + PrtScr. What about just PrtScr? You can call gnome-screenshot without any of those options to capture everything on all of your displays.

That’s a nice and flexible way of taking screenshots and it can cover all of my needs. The only problem is the fact that I need to use Terminal each time I want to make a screenshot and the command itself would be pretty long to type fast. GNOME allows us to solve such problems by adding custom shortcuts which can be mapped to any command or set of commands we wish to invoke.

Custom Shortcuts

Obviously, the most efficient way to take a screenshot is to use a shortcut but using default shortcuts means you have no control over where your screenshots are saved and what file names they’ll be assigned with. Luckily for us, it’s easy to map shortcuts to Terminal commands, which allows us to have the convenience of dedicated shortcuts and the flexibility of the command line interface which gnome-screenshot provides.

Illustration
Illustration

Here is an example of a command that can be used to take an “area” screenshot and save it in a custom directory under a custom name:

sh -c 'gnome-screenshot --area --file=/home/igor/nextcloud/screenshots/$(date --iso-8601=seconds).png'

We need to generate an unique name for each screenshot, and that can be done with the following sub-command:

date --iso-8601=seconds

It gives us the following output:

2020-10-20T17:32:30+07:00

At this point, I have nothing to complain about. Those custom shortcuts do exactly what I need.

Conclusion

Command-line interface is the ultimate source of productivity in any Unix-like system and custom shortcuts allow us to utilize the flexibility of a terminal while working with from GUI. I don’t have any other custom shortcuts except for screenshot-related ones but there are many potential use cases for binding your favorite commands and scripts to the specific keyboard shortcuts and they can serve as a bridge between a terminal and a graphical interface.

Linux   GNOME

This page doesn't show ads and the reasons are simple:

  • Most people don't want to see ads (what a surprise)
  • Ads can track you and violate your privacy
  • Ads is the main reason why many websites are so slow

If you find this content valuable or you want to see more content like this, you can leave a tip with bitcoin:

34CXtg7c4Vbw8DZjAwFQVsrbu9eDEbTzbA
bitcoin tips QR