Pressing printscreen or clickin the screenshot will capture both screens, what if I only want the active monitor display captured, is it feasible? Or should I use shutter or sth?

enter image description here

So not spaces of the same screen, but dual monitor system two screens.

  • Your screens seem of the same (y-) resolution, and aligned, is that correct? – Jacob Vlijm May 28 '16 at 8:52
  • Yes, they are... – Mookey May 28 '16 at 9:05
  • Nice, writing an answer. – Jacob Vlijm May 28 '16 at 9:06

To only shoot the current screen is not the default behaviour, nor is it an option in gnome-screenshot, nor any other screenshot application as far as I know.

Like practically anything however, it can be scripted.

An example

The script further below will:

  • take a screenshot
  • automatically create a (numbered) image in an arbitrary directory
  • automatically crop the image to the section of the screen you are currently on (retrieved from the mouse position), and create a cropped image named:


To prevent overwriting earlier screenshots, these cropped images are numbered like their oroginals.


enter image description here

if I am on the left screen:

enter image description here

if I am on the right screen:

enter image description here

The script

#!/usr/bin/env python3
import os
from PIL import Image
import subprocess

# ---set the name of your (automatically numbered) screenshots (no extension)
imagename = "screenshot"
# ---set the path to where you (want to) save your screenshots
savepath = "/home/jacob/Bureaublad"

def get(cmd):
    return subprocess.check_output(cmd).decode("utf-8")

n = 1 
while True:
    name = imagename+"_"+str(n)+".png"
    path = os.path.join(savepath, name)
    if os.path.exists(path):
        n += 1

# make the shot
subprocess.call(["gnome-screenshot", "-f", path])
# get the width of the left screen
screenborder = [int(n) for n in [s for s in get("xrandr").split()\
                if "+0+0" in s][0].split("+")[0].split("x")]
# read the screenshot
im = Image.open(path)
width, height = im.size
# get the mouse position
mousepos = int(get(["xdotool", "getmouselocation"]).split()[0].split(":")[1])
top = 0
bottom = height

if mousepos <= screenborder[0]:
    left = 0
    right = screenborder[0]
    left = screenborder[0]
    right = width
# create the image
im.crop((left, top, right, bottom)).save(os.path.join(savepath, "cropped_"+name))

How to use

  1. The script needs xdotool, to get the mouse position:

    sudo apt-get install xdotool

    Furthermore, not sure if python3-pil is installed by default:

    sudo apt-get install python3-pil
  2. Copy the script above into an empty file, save it as crop_screenshot.py
  3. In the head section of the script, set the desired name of the screenshot and the directory you use for your screenshots:

    # ---set the name of your (automatically numbered) screenshots (no extension)
    imagename = "screenshot"
    # ---set the path to where you (want to) save your screenshots
    savepath = "/home/jacob/Bureaublad"
  4. Test- run the script from a terminal:

    python3 /path/to/crop_screenshot.py

    The result:

    enter image description here

  5. If all works fine, add it to a shortcut. Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/crop_screenshot.py


The script, as it is, simply splits the image on the width of your left screen. This is sufficient, because your screens are of the same y-resolution and aligned.

The script can however very well be edited to work with any screen arrangement, with any number of screens, as long as the screens are arranged in a non-overlapping arrangement. The math is a bit more complicated in that case however.

If anyone is interested, I will add it later.

  • Thanks, I'll try when I find time, and thanks for the effort, I'm accepting this. – Mookey May 28 '16 at 18:33

Not withstanding the elegant script above, on ubuntu 16.04 I found that alt-print-screen, as desribed in: Print Screen captures two Spaces not one works. Actually this just prints the current window. If the aim is to capture a background I don't think it will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.