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.
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:
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:
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
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))
How to use
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
Copy the script above into an empty file, save it as 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
Note
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.
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.
One option is to press Shift + PrtSc and then drag the cross from one corner of the monitor to the other corner. Release and it takes a screenshot of that area.
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:
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.
screenshot
if I am on the left screen:
if I am on the right screen:
The script
How to use
The script needs
xdotool
, to get the mouse position:Furthermore, not sure if
python3-pil
is installed by default: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:
Test- run the script from a terminal:
The result:
If all works fine, add it to a shortcut. Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
Note
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.
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.
One option is to press Shift + PrtSc and then drag the cross from one corner of the monitor to the other corner. Release and it takes a screenshot of that area.