-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmscrot
executable file
·87 lines (77 loc) · 2.27 KB
/
dmscrot
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
82
83
84
85
86
87
#!/usr/bin/env bash
#
# Script name: dmscrot
# Description: Choose type of screenshot to take with maim.
# Dependencies: dmenu, maim, tee, xdotool, xclip
# GitLab: https://www.gitlab.com/dwt1/dmscripts
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
# Contributors: Derek Taylor
# Simon Ingelsson
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
# if certain things happen, which is a good thing. Otherwise, we can
# get hidden bugs that are hard to discover.
set -euo pipefail
# Specifying a directory to save our screenshots.
SCROTDIR="$HOME/Screenshots"
# Makes sure the directory exists.
mkdir -p "${SCROTDIR}"
# FIX: STAMP will be set to the time when this script was executed and not when the actual screenshot is taken
STAMP=$(date '+%Y%m%d-%H%M%S')
MAIM_ARGS=""
MAIM_FILE=""
# Get monitors and their settings for maim
DISPLAYS=$(xrandr --listactivemonitors | grep '+' | awk '{print $4, $3}' | awk -F'[x/+* ]' '{print $1,$2"x"$4"+"$6"+"$7}')
# What modes do we have
declare -a modes=(
"Fullscreen"
"Active window"
"Selected region"
)
# Add monitor data
IFS=$'\n'
declare -A DISP
for i in ${DISPLAYS}; do
name=$(echo ${i}|awk '{print $1}')
rest="$(echo ${i}|awk '{print $2}')"
modes[${#modes[@]}]="${name}"
DISP[${name}]="${rest}"
done
unset IFS
target=$(printf '%s\n' "${modes[@]}" | dmenu -i -l 20 -p 'Take screenshot of:') || exit 1
case "$target" in
'Fullscreen')
MAIM_ARGS=""
MAIM_FILE="${SCROTDIR}/scrot-full-${STAMP}.png"
;;
'Active window')
active_window=$(xdotool getactivewindow)
MAIM_ARGS="-i ${active_window}"
MAIM_FILE="${SCROTDIR}/scrot-window-${STAMP}.png"
;;
'Selected region')
MAIM_ARGS="-s"
MAIM_FILE="${SCROTDIR}/scrot-region-${STAMP}.png"
;;
*)
MAIM_ARGS="-g ${DISP[${target}]}"
MAIM_FILE="${SCROTDIR}/scrot-${target}-${STAMP}.png"
;;
esac
declare -a destination=( "File" "Clipboard" "Both" )
dest=$(printf '%s\n' "${destination[@]}" | dmenu -i -l 20 -p 'Destination:') || exit 1
case "$dest" in
'File')
maim ${MAIM_ARGS} "${MAIM_FILE}"
echo $?
;;
'Clipboard')
maim ${MAIM_ARGS} | xclip -selection clipboard -t image/png
;;
'Both')
maim ${MAIM_ARGS} | tee "${MAIM_FILE}" | xclip -selection clipboard -t image/png
;;
*)
exit 1
;;
esac
exit 0