-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtake-screenshot.sh
53 lines (39 loc) · 1.6 KB
/
take-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
#!/bin/bash
filePath=~/Pictures/Screenshots/$(date +"%H:%M")_$(date +"%m-%d-%y").png
tempFilePath=~/Pictures/Screenshots/temp.png
gradientFilePath=~/Pictures/Screenshots/gradient.png
borderSize=5
# Find available colors here: https://imagemagick.org/script/color.php
# HEX and RGB color codes are supported as well
gradientColor1=yellow
gradientColor2=red
command_exists() {
command -v "$1" &> /dev/null
}
handle_not_installed() {
echo "'$1' is not installed. Exiting..."
exit 1
}
mkdir -p ~/Pictures/Screenshots &> /dev/null
if ! command_exists scrot; then
handle_not_installed scrot
elif ! command_exists xclip; then
handle_not_installed xclip
elif ! command_exists magick; then
handle_not_installed ImageMagick
fi
# Take screenshot
scrot --select --line color=#FFFFFF --display :0 --quality 100 --file $tempFilePath
# Get the dimensions of the screenshot
width=$(identify -format "%w" $tempFilePath)
height=$(identify -format "%h" $tempFilePath)
# Create a gradient image with the same size as the screenshot, with added border size
magick -size $((width + 2 * borderSize))x$((height + 2 * borderSize)) gradient:$gradientColor1-$gradientColor2 $gradientFilePath
# Add a border around the screenshot by overlaying gradient image
magick $tempFilePath -bordercolor none -border $borderSize $gradientFilePath -compose DstOver -composite $filePath
# Copy file to clipboard
/usr/bin/cat $filePath | xclip -selection clipboard -target image/png -i
# Send notification
notify-send "Saved screenshot to $filePath. File copied to clipboard."
# Clean up temporary files
rm $tempFilePath $gradientFilePath