-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot.sh
executable file
·68 lines (55 loc) · 2.05 KB
/
screenshot.sh
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
#!/bin/sh
MAX_DELAY=15
DMENU_FONT="DejaVuSansMono:size=9:antialias=true:autohint=true"
DMENU_NB="#2c1a1a"
DMENU_NF="#efefef"
DMENU_SB="#5cd5ff"
DMENU_SF="#000000"
delay=$(seq 0 $MAX_DELAY | dmenu -p "Screenshot delay:" -nf $DMENU_FONT -nb $DMENU_NB -nf $DMENU_NF -sb $DMENU_SB -sf $DMENU_SF)
if [ -z "$delay" ]; then
exit 0
fi
SELECT="Select area to capture"
ONE_SCREEN="Capture a screen"
ALL_SCREENS="Capture all screens"
capture=$(echo -e "$SELECT\n$ONE_SCREEN\n$ALL_SCREENS" | dmenu -nf $DMENU_FONT -nb $DMENU_NB -nf $DMENU_NF -sb $DMENU_SB -sf $DMENU_SF)
if [ -z "$capture" ]; then
exit 0
fi
tmp_file="/tmp/$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo).png"
if [ "$capture" == "$SELECT" ]; then
GEOMETRY=$(sx4 -c "#5cd5ff")
if [ -z "$GEOMETRY" ]; then
exit 0;
fi
sleep $delay
sxot --geom "$GEOMETRY" | ffmpeg -i - "$tmp_file"
elif [ "$capture" == "$ONE_SCREEN" ]; then
monitor=$(xrandr --listactivemonitors | tail -n+2 | awk -F + '{ print $3,$4,$1 }' | sort | awk '{ print substr($4, 0, 1) }' | dmenu -nf $DMENU_FONT -nb $DMENU_NB -nf $DMENU_NF -sb $DMENU_SB -sf $DMENU_SF)
if [ -z "$monitor" ]; then
exit 0
fi
sleep "$delay"
sxot --monitor "$monitor" | ffmpeg -i - "$tmp_file"
else
sleep "$delay"
sxot | ffmpeg -i - "$tmp_file"
fi
COPY_TO_CLIPBOARD="Copy screenshot to clipboard"
SAVE_TO_FILE="Save screenshot to file"
output=$(echo -e "$COPY_TO_CLIPBOARD\n$SAVE_TO_FILE" | dmenu -nf $DMENU_FONT -nb $DMENU_NB -nf $DMENU_NF -sb $DMENU_SB -sf $DMENU_SF)
if [ -z "$output" ]; then
rm "$tmp_file"
exit 0
fi
if [ "$output" == "$COPY_TO_CLIPBOARD" ]; then
cat "$tmp_file" | xclip -selection clipboard -target image/png
notify-send "Screenshot copied to clipboard" -h "string:image-path:$tmp_file" -t 2000
rm "$tmp_file"
else
output_file="$(zenity --file-selection --save --title="Save screenshot as:")"
if [ ! -z "$output_file" ]; then
notify-send "Saving screenshot as $output_file" -h "string:image-path:$tmp_file" -t 2000
mv "$tmp_file" "$output_file"
fi
fi