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?
So not spaces of the same screen, but dual monitor system two screens.
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?
So not spaces of the same screen, but dual monitor system two screens.
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.
The script further below will:
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:
cropped_<image>.png
To prevent overwriting earlier screenshots, these cropped images are numbered like their oroginals.
screenshot
if I am on the left screen:
if I am on the right screen:
#!/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
else:
break
# 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]
else:
left = screenborder[0]
right = width
# create the image
im.crop((left, top, right, bottom)).save(os.path.join(savepath, "cropped_"+name))
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
crop_screenshot.py
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"
Test- run the script from a terminal:
python3 /path/to/crop_screenshot.py
The result:
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.