A few words of thanks would be greatly appreciated.

X-Window: Screenshots

How to take a screen capture when no screenshot tool (Ksnapshot, ...) is installed on your system?
The ImageMagick* package (binary available for most distributions **) contains a dozen commands dedicated to image manipulation.
The one that interests us here is the import command.
import can be called in 2 ways:
  • $ import file.ext
  • $ import -window WinId file.ext

I invite you to consult the manual (man 1 import) to learn about the other options of this command.

The first call means that you want to capture and store a screenshot in the file.ext
  • Where .ext defines the format of image compression: png, gif, jpg, etc..

Once the command issued, the pointer turns into a cross. We then have two possibilities:
  • Define an area to capture with a click and drag
  • Define a window to capture by clicking on the border.

The second call, allows you to specify the window you want to capture through its name or ID.
Where the "root" parameter defines the Desktop.
Knowing this, it is possible to generate a small script to facilitate the use of the import command:
#{{{ Vérification de l'existence du binaire import
if [ ! -x ${import} ]; then
  echo "${import} not found!"
  exit 1

#{{{ Création du dossier "captures" si besoin
mkdir -p ~/captures

#{{{ Génération du nom de la capture
name=$(date +"%Y.%m.%d-%H.%M.%S")

#{{{ Traitement (basique) de l'argument
if [ $# -eq 1 ]; then
  option=" -window $1"

#{{{ Capture
$import $option ~/captures/$name.png

The purpose of this script:
  • Verify the presence of the binary.
  • Creating a folder to store your screenshots in the home directory of the user.
  • Capture the:
    • entire screen if the "root" option is given,
    • the desired window if its name or Id is passed as a parameter,
    • a particular area with the mouse if no argument,
  • Save the screenshot in the "png" format as: year.month.day-hours.minutes.seconds.png

All that remains is to configure the following keyboard shortcuts (KHotKeys under KDE)
  • <alt> + <print> -> capture.sh
  • <print> -> capture.sh root

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « X-Window: Screenshots », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).