-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
82 lines (68 loc) · 2.16 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
"""Take screenshots or snips using Gnome screenshot utiliy directly from the launcher.\
Select between a snip, a fullscreen or window only screenshot, to save or to keep on clipboard.
Auto saved screenshots are located in XDG_PICTURES_DIR ('Pictures' folder).
Icon by icons8.com"""
import os
import subprocess
import tempfile
from shutil import which
from albert import FuncAction, Item
__title__ = "Snip"
__version__ = "0.4.0"
__triggers__ = "ss "
__authors__ = "Fabián Pérez"
__exec_deps__ = ["gnome-screenshot"]
iconPath = os.path.dirname(__file__)+"/icon.png"
def handleQuery(query):
if query.isTriggered:
return [
Item(
id = "%s-area-of-screen" % __title__,
icon = iconPath,
text = "Snip screen",
subtext = "Capture a rectacle drawed with your mouse",
actions = [
FuncAction(
"Capture to clipboard",
lambda: doScreenshot(["-a -c"])
),
FuncAction(
"Capture and save in Pictures",
lambda: doScreenshot(["-a"])
),
]
),
Item(
id = "%s-whole-screen" % __title__,
icon = iconPath,
text = "Take screenshot",
subtext = "Save a screenshot in Pictures",
actions = [
FuncAction(
"Take full screenshot",
lambda: doScreenshot(["-p"])
),
FuncAction(
"Take screenshot without showing the pointer",
lambda: doScreenshot([])
),
FuncAction(
"Take screenshot of actual window only",
lambda: doScreenshot(["-w --border-effect=shadow"])
),
]
),
]
def getScreenshotDirectory():
if which("xdg-user-dir") is None:
return tempfile.gettempdir()
proc = subprocess.run(["xdg-user-dir", "PICTURES"], stdout=subprocess.PIPE)
pictureDirectory = proc.stdout.decode("utf-8")
if pictureDirectory:
return pictureDirectory.strip()
return tempfile.gettempdir()
def doScreenshot(args):
path = getScreenshotDirectory()
command = "sleep 0.1 && gnome-screenshot %s " % path
subprocess.Popen(command + " ".join(args), shell=True)