#!/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))
如何使用
脚本需要xdotool, 来获取鼠标位置:
sudo apt-get install xdotool
此外,不确定是否python3-pil默认安装:
sudo apt-get install python3-pil
将上面的脚本复制到一个空文件中,另存为crop_screenshot.py
在脚本的 head 部分,设置所需的屏幕截图名称和用于屏幕截图的目录:
# ---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"
gnome-screenshot
据我所知,仅拍摄当前屏幕不是默认行为,也不是 中的选项,也不是任何其他屏幕截图应用程序。然而,就像几乎任何东西一样,它可以编写脚本。
一个例子
下面的脚本将:
自动将图像裁剪到您当前所在的屏幕部分(从鼠标位置检索),并创建一个名为:
为防止覆盖早期的屏幕截图,这些裁剪后的图像会像它们的原始图像一样编号。
截屏
如果我在左侧屏幕上:
如果我在正确的屏幕上:
剧本
如何使用
脚本需要
xdotool
, 来获取鼠标位置:此外,不确定是否
python3-pil
默认安装:crop_screenshot.py
在脚本的 head 部分,设置所需的屏幕截图名称和用于屏幕截图的目录:
测试 - 从终端运行脚本:
结果:
如果一切正常,请将其添加到快捷方式。选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。单击“+”并添加命令:
笔记
实际上,该脚本只是将图像拆分为左侧屏幕的宽度。这已经足够了,因为您的屏幕具有相同的 y 分辨率并已对齐。
然而,脚本可以很好地编辑为与任何屏幕排列、任意数量的屏幕一起使用,只要屏幕以非重叠排列排列即可。然而,在这种情况下,数学有点复杂。
如果有人有兴趣,我稍后再补充。
尽管上面有优雅的脚本,但在 ubuntu 16.04 上,我发现 alt-print-screen,如所述: Print Screen captures two Spaces not one works。实际上这只是打印当前窗口。如果目的是捕捉背景,我认为它不会起作用。
一种选择是按下Shift + PrtSc然后将十字从显示器的一个角拖到另一个角。释放它会截取该区域的屏幕截图。