-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreen_shot.sh
executable file
·81 lines (68 loc) · 2.05 KB
/
screen_shot.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Create three keyboard shortcuts in Gnome settings
# Screen shot area - /home/twilight/Documents/git/scripts/screen_shot.sh area "/optional/alternate/path/to/save/screenshots" - Shift+Ctrl+1
# Screen shot full screen - /home/twilight/Documents/git/scripts/screen_shot.sh full "/optional/alternate/path/to/save/screenshots" - Shift+Ctrl+2
# Screen shot window - /home/twilight/Documents/git/scripts/screen_shot.sh window "/optional/alternate/path/to/save/screenshots" - Shift+Ctrl+3
# Returns the current time stamp in format 2022-07-23T14-56-03Z
zulu_time(){
/bin/echo "$(/bin/date -u "+%Y-%m-%dT%H-%M-%SZ")"
}
if [[ -n "$2" ]]; then
SCREENSHOT_PATH="$2"
else
SCREENSHOT_PATH="$HOME/Pictures"
fi
enableLog=false
[[ "$3" == true ]] && enableLog=true
file_name="screenshot_$(zulu_time).png"
out_directory="$SCREENSHOT_PATH"
log_file="$SCREENSHOT_PATH/screenshots.log"
# Log some text to the log file. Params:
# 1. The text to log
log() {
if [[ "$enableLog" == true ]]; then
/bin/echo "$(zulu_time) $1" >> "$log_file"
echo "$1"
fi
}
GNOME_CMD=(
"/usr/bin/gnome-screenshot"
"--clipboard"
"--include-pointer"
"--delay" "0"
"--file" "$out_directory/$file_name"
)
KDE_CMD=(
"/usr/bin/spectacle"
"--background"
"--copy-image"
"--delay" "0"
"--nonotify"
"--output" "$out_directory/$file_name"
)
case "$1" in
area)
LOG_STRING=area
GNOME_CMD+=("--area")
KDE_CMD+=("--region");;
window)
LOG_STRING=window
GNOME_CMD+=("--window")
KDE_CMD+=("--activewindow");;
full)
LOG_STRING="full screen"
KDE_CMD+=("--fullscreen");;
*)
log "Supported options: area, window, and full."
exit 1;;
esac
log "Taking $LOG_STRING screenshot"
if [ "$XDG_CURRENT_DESKTOP" = "GNOME" ]; then
"${GNOME_CMD[@]}"
elif [ "$XDG_CURRENT_DESKTOP" = "KDE" ]; then
"${KDE_CMD[@]}"
else
log "Unsupported desktop environment: $XDG_CURRENT_DESKTOP"
exit 1
fi
log "Screenshot $LOG_STRING saved to \"$out_directory/$file_name\""