-
Notifications
You must be signed in to change notification settings - Fork 0
/
take-screenshot
executable file
·74 lines (67 loc) · 1.91 KB
/
take-screenshot
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
#!/usr/bin/env bash
#
# rofi menu to take screenshots with maim
#
# usage: take-screenshot
#
# $ take-screenshot
# This option will make the script exit when there is an error
set -o errexit
# This option will make the script exit when last command threw an error
set -o pipefail
# This option will make the script exit when it tries to use an unset variable
set -o nounset
# Trace what gets executed
# set -o xtrace
dir_screenshots="$HOME/Pictures/Screenshots"
file_extension="png"
filename=""
filename_prefix=""
maim_option=""
selection=-1
# create screenshot directory
mkdir -p "${dir_screenshots}"
# start
case $(echo "[1] Fullscreen|[2] Selection|[3] Active Window|[4] High Quality|[5] Open screenshots directory" | rofi -sep '|' -auto-select -no-fixed-num-lines -dmenu -p "Take Screenshot" -i) in
'[1] Fullscreen')
selection=1
filename_prefix="default"
maim_option=""
dunstify_title_postfix="Fullscreen"
;;
'[2] Selection')
selection=2
filename_prefix="selection"
maim_option="-s"
dunstify_title_postfix="Selection"
;;
'[3] Active Window')
selection=3
filename_prefix="active"
maim_option="-i $(xdotool getactivewindow)"
dunstify_title_postfix="Active Window"
;;
'[4] High Quality')
selection=4
filename_prefix="hq"
maim_option="-m 1"
dunstify_title_postfix="High Quality"
;;
'[5] Open screenshots directory')
selection=0
;;
esac
# put together all the pieces for the filename
filename="${filename_prefix}-$(date -u +"%Y-%m-%d-%T").${file_extension}"
# Do nothing by default
if (( "${selection}" == 0 )); then
# Open nnn by default
$TERM -e nnn "${dir_screenshots}" &
elif (( "${selection}" > 0 )); then
# Take screenshot
maim -q $maim_option "${filename}"
mv "${filename}" "${dir_screenshots}"
# Display notification
dunstify "Screenshot: ${dunstify_title_postfix}" "${filename} saved in ${dir_screenshots} directory"
fi
exit $?