DEV Community

Fomalhaut Weisszwerg
Fomalhaut Weisszwerg

Posted on

How to capture a screenshot of the single window you want (using command line).

Introduction.

GIMP is very useful, but sometimes doing not well. Or you find a way to capture screenshots via CLI, but the way using xwd command does not work.

In such a case, this article might be your friend.
Also it would be useful when you use some environment that does not have the "ScreenShot" key, such as a laptop.

This article provides you the way to capture screenshots using xwininfo and ImageMagick.

Prerequisite.

As previous, xwininfo and import of ImageMagick are required.

On Debian and Ubuntu, it needs to install x11-utils and imagemagick packages. To install these, run:

sudo apt install x11-utils imagemagick
Enter fullscreen mode Exit fullscreen mode

Now, we are ready to do!

Step 1. Get "Window ID" using xwininfo.

To get "Window ID", run following command in a terminal:

xwininfo
Enter fullscreen mode Exit fullscreen mode

Immediately prompts shown like following:

prompts of xwininfo

Select the window you want to capture by clicking a mouse. Then information of the selected window is displayed following the prompt.

Image description

The most important is the first line including "Window id: ...". So the hexadecimal is a Window ID. In the previous example, Window ID is 0x4000001!

Step 2. Capture a screenshot using import.

To capture a screenshot of the selected window using import command, it needs to pass "Window ID" with -window option.

Run:

import -window 0x4000001 screenshot.jpg
Enter fullscreen mode Exit fullscreen mode

Finally, the screenshot is saved in the current directory!

screenshot of windows id 0x4000001

One more thing.

I will show you "How to capture the whole desktop" by CLI.

Passing root keyword to -window option:

import -window root screenshot_whole_desktop.jpg
Enter fullscreen mode Exit fullscreen mode

Enjoy!

Oldest comments (0)