2022-12-20 00:15:21 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# ***This script was made by Clay Gomera (Drake)***
|
2023-08-08 01:04:48 +00:00
|
|
|
# - Description: A simple screenshot/screencast dmenu script
|
|
|
|
# - Dependencies: maim, splop, ffmpeg, dmenu, libnotify
|
2022-12-20 00:15:21 +00:00
|
|
|
|
2023-10-03 19:16:54 +00:00
|
|
|
#######################################
|
|
|
|
## Screenshot & Screencast Directory ##
|
|
|
|
#######################################
|
2023-10-03 14:40:20 +00:00
|
|
|
SHOTDIR="$XDG_PICTURES_DIR/screenshots"
|
|
|
|
CASTDIR="$XDG_VIDEOS_DIR/screencasts"
|
2023-10-03 19:16:54 +00:00
|
|
|
[ ! -d "$SHOTDIR" ] && [ ! -d "$CASTDIR" ] && mkdir -p "$SHOTDIR" "$CASTDIR" || echo
|
|
|
|
|
|
|
|
######################
|
|
|
|
## Format Variables ##
|
|
|
|
######################
|
|
|
|
image_formats="jpg\npng"
|
|
|
|
video_formats="mp4\nmkv"
|
2023-10-03 14:40:20 +00:00
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#######################
|
2023-08-08 01:04:48 +00:00
|
|
|
## Main menu choices ##
|
2023-09-04 17:36:18 +00:00
|
|
|
#######################
|
2023-10-03 14:40:20 +00:00
|
|
|
mcho1=" Take a screenshot"
|
|
|
|
mcho2=" Record the screen"
|
|
|
|
mcho3=" Stop recording"
|
|
|
|
mcho4=" Exit"
|
|
|
|
mchos="$mcho1\n$mcho2\n$mcho3\n$mcho4"
|
2022-12-20 00:15:21 +00:00
|
|
|
|
2023-10-03 19:16:54 +00:00
|
|
|
##########################
|
|
|
|
## Main submenu choices ##
|
|
|
|
##########################
|
|
|
|
mscho1=" Capture the entire screen"
|
|
|
|
mscho2=" Capture the entire screen (With delay)"
|
|
|
|
mscho3=" Capture area"
|
|
|
|
mscho4=" Capture active window"
|
|
|
|
mscho5=" Exit"
|
|
|
|
mschos="$mscho1\n$mscho2\n$mscho3\n$mscho4\n$mscho5"
|
|
|
|
|
|
|
|
###############################
|
|
|
|
## Save/clip submenu choices ##
|
|
|
|
###############################
|
|
|
|
svcho1=" Copy to clipboard"
|
|
|
|
svcho2=" Save to $SHOTDIR"
|
|
|
|
svchos="$svcho1\n$svcho2"
|
2023-08-08 01:04:48 +00:00
|
|
|
|
2023-10-05 08:11:11 +00:00
|
|
|
######################
|
|
|
|
## Delay subsubmenu ##
|
|
|
|
######################
|
2023-06-24 17:00:22 +00:00
|
|
|
del1=" 3 sec delay"
|
|
|
|
del2=" 5 sec delay"
|
|
|
|
del3=" 10 sec delay"
|
2022-12-20 00:15:21 +00:00
|
|
|
dels="$del1\n$del2\n$del3"
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-10-03 19:16:54 +00:00
|
|
|
## This function will check for dependencies
|
|
|
|
#####
|
|
|
|
check_dependencies() {
|
|
|
|
local dependencies=("maim" "ffmpeg" "dmenu" "notify-send" "xclip" "xdotool")
|
|
|
|
for dep in "${dependencies[@]}"; do
|
|
|
|
if ! command -v "$dep" &>/dev/null; then
|
|
|
|
echo "$dep is required but not installed. Please install it and try again."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#####
|
|
|
|
## This function uses the svchos variable to ask the user what to do with the
|
2023-09-04 17:36:18 +00:00
|
|
|
## screenshot
|
|
|
|
#####
|
2023-10-03 19:16:54 +00:00
|
|
|
fsvchos() {
|
|
|
|
svchoice=$(echo -e "$svchos" | dmenu -i -l 2 -p " What do you want to do with this screenshot?")
|
2023-08-08 01:04:48 +00:00
|
|
|
}
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-10-03 14:40:20 +00:00
|
|
|
## This function uses the dels variable to ask the user which delay option to
|
2023-09-04 17:36:18 +00:00
|
|
|
## choose
|
|
|
|
#####
|
2023-08-08 01:04:48 +00:00
|
|
|
fdel() {
|
|
|
|
del=$(echo -e "$dels" | dmenu -i -p " Select Delay")
|
|
|
|
}
|
|
|
|
|
2023-10-03 19:16:54 +00:00
|
|
|
#####
|
|
|
|
## This function allows the user to choose the screenshot format
|
|
|
|
#####
|
|
|
|
fimage_format() {
|
|
|
|
image_format=$(echo -e "$image_formats" | dmenu -i -p " Choose screenshot format")
|
|
|
|
}
|
|
|
|
|
|
|
|
#####
|
|
|
|
## This function allows the user to choose the recording format
|
|
|
|
#####
|
|
|
|
fvideo_format() {
|
|
|
|
video_format=$(echo -e "$video_formats" | dmenu -i -p " Choose video format")
|
|
|
|
}
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-10-03 14:40:20 +00:00
|
|
|
## This function does a full screen screenshot without delay, depending on what
|
2023-10-03 19:16:54 +00:00
|
|
|
## the user chooses on the fsvchos function, the screenshot will be saved to the
|
2023-10-03 14:40:20 +00:00
|
|
|
## clipboard or to $SHOTDIR
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-08-08 01:04:48 +00:00
|
|
|
shot_screen() {
|
2023-10-03 19:16:54 +00:00
|
|
|
fimage_format
|
|
|
|
fsvchos
|
|
|
|
if [ "$svchoice" = "$svcho1" ]; then
|
|
|
|
maim | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard"
|
|
|
|
elif [ "$svchoice" = "$svcho2" ]; then
|
|
|
|
maim -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved"
|
2023-08-08 01:04:48 +00:00
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-10-03 14:40:20 +00:00
|
|
|
## This function does a full screen screenshot with delay, depending on what the
|
2023-10-03 19:16:54 +00:00
|
|
|
## user chooses on the fsvchos function, the screenshot will be saved to the
|
2023-10-03 14:40:20 +00:00
|
|
|
## clipboard or to $SHOTDIR. And depending on what the user chooses on the fdel
|
|
|
|
## function, the delay will be between 3 and 10 seconds
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-08-08 01:04:48 +00:00
|
|
|
shot_screen_delay() {
|
2023-10-03 19:16:54 +00:00
|
|
|
fimage_format
|
|
|
|
fsvchos
|
|
|
|
fdel
|
|
|
|
case $del in
|
|
|
|
"$del1")
|
|
|
|
for i in 3 2 1
|
|
|
|
do
|
|
|
|
notify-send -d 1 "Capturing in $i.."
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
"$del2")
|
|
|
|
for i in 5 4 3 2 1
|
|
|
|
do
|
|
|
|
notify-send -d 1 "Capturing in $i.."
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
"$del3")
|
|
|
|
for i in 10 9 8 7 6 5 4 3 2 1
|
|
|
|
do
|
|
|
|
notify-send -d 1 "Capturing in $i.."
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$svchoice" = "$svcho1" ]; then
|
|
|
|
maim | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard";
|
|
|
|
elif [ "$svchoice" = "$svcho2" ]; then
|
|
|
|
maim -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved to $SHOTDIR";
|
2023-08-08 01:04:48 +00:00
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-10-03 14:40:20 +00:00
|
|
|
## This function allows the user to select the area on the screen to screenshot
|
2023-10-03 19:16:54 +00:00
|
|
|
## depending on what the user chooses on the fsvchos function, the screenshot will
|
2023-10-03 14:40:20 +00:00
|
|
|
## be saved to the clipboard or to $SHOTDIR
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-08-08 01:04:48 +00:00
|
|
|
shot_area() {
|
2023-10-03 19:16:54 +00:00
|
|
|
fimage_format
|
|
|
|
fsvchos
|
|
|
|
if [ "$svchoice" = "$svcho1" ]; then
|
|
|
|
maim -s | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard";
|
|
|
|
elif [ "$svchoice" = "$svcho2" ]; then
|
|
|
|
maim -s -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved to $SHOTDIR";
|
2023-08-08 01:04:48 +00:00
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-10-03 14:40:20 +00:00
|
|
|
## This function does a screenshot of the currently active window, depending
|
2023-10-03 19:16:54 +00:00
|
|
|
## on what the user chooses on the fsvchos function, the screenshot will be
|
2023-10-03 14:40:20 +00:00
|
|
|
## saved to the clipboard or to $SHOTDIR
|
2023-09-04 17:36:18 +00:00
|
|
|
#####
|
2023-08-08 01:04:48 +00:00
|
|
|
shot_window() {
|
2023-10-03 19:16:54 +00:00
|
|
|
fimage_format
|
|
|
|
fsvchos
|
|
|
|
if [ "$svchoice" = "$svcho1" ]; then
|
|
|
|
maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/"$image_format" && notify-send "Screenshot saved to clipboard";
|
|
|
|
elif [ "$svchoice" = "$svcho2" ]; then
|
|
|
|
maim -i "$(xdotool getactivewindow)" -f "$image_format" "$SHOTDIR/$(date +%s).$image_format" && notify-send "Screenshot saved to $SHOTDIR";
|
2023-08-08 01:04:48 +00:00
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-10-03 14:40:20 +00:00
|
|
|
#####
|
|
|
|
## This function uses ffmpeg to record the screen, It will check if ffmpeg is
|
|
|
|
## already running (already recording), to prevent the user from executing
|
|
|
|
## another ffmpeg instance, if it's not running, it will grab the screen
|
|
|
|
## resolution with xdpyinfo and use it to record the screen with ffmpeg.
|
|
|
|
#####
|
2023-10-03 19:16:54 +00:00
|
|
|
rec_screen() {
|
|
|
|
fvideo_format
|
2023-10-03 14:40:20 +00:00
|
|
|
if pgrep -x "ffmpeg" > /dev/null; then
|
|
|
|
notify-send "A screen recording is already in progress."
|
|
|
|
else
|
2023-10-03 19:16:54 +00:00
|
|
|
filename="$CASTDIR/$(date +%s).$video_format"
|
2023-10-03 14:40:20 +00:00
|
|
|
resolution="$(xdpyinfo | grep dimensions | awk '{print $2}')"
|
|
|
|
ffmpeg -f x11grab -s "$resolution" -i :0.0 -c:v libx264 -preset ultrafast -qp 0 "$filename" &
|
|
|
|
notify-send "Screen recording started."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-10-03 19:16:54 +00:00
|
|
|
#####
|
|
|
|
## This function will record the screen with a given delay
|
|
|
|
#####
|
|
|
|
rec_screen_delay() {
|
|
|
|
fvideo_format
|
|
|
|
fdel
|
|
|
|
case $del in
|
|
|
|
"$del1")
|
|
|
|
for i in 3 2 1
|
|
|
|
do
|
|
|
|
notify-send -d 1 "Starting in $i.."
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
"$del2")
|
|
|
|
for i in 5 4 3 2 1
|
|
|
|
do
|
|
|
|
notify-send -d 1 "Starting in $i.."
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
"$del3")
|
|
|
|
for i in 10 9 8 7 6 5 4 3 2 1
|
|
|
|
do
|
|
|
|
notify-send -d 1 "Starting in $i.."
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if pgrep -x "ffmpeg" > /dev/null; then
|
|
|
|
notify-send "A screen recording is already in progress."
|
|
|
|
else
|
|
|
|
filename="$CASTDIR/$(date +%s).$video_format"
|
|
|
|
resolution="$(xdpyinfo | grep dimensions | awk '{print $2}')"
|
|
|
|
ffmpeg -f x11grab -s "$resolution" -i :0.0 -c:v libx264 -preset ultrafast -qp 0 "$filename" &
|
|
|
|
notify-send "Screen recording started"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-10-03 14:40:20 +00:00
|
|
|
#####
|
|
|
|
## This function stops screen recording, it first checks if ffmpeg is already
|
|
|
|
## running (already recording), to only stop a recording if there's an ffmpeg
|
|
|
|
## instance running
|
|
|
|
#####
|
|
|
|
stop_recording() {
|
|
|
|
if pgrep -x "ffmpeg" > /dev/null; then
|
|
|
|
pkill -f "ffmpeg -f x11grab"
|
|
|
|
notify-send "Screen recording stopped. Video saved to $CASTDIR"
|
|
|
|
else
|
|
|
|
notify-send "You aren't recording anything at the moment"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-09-04 17:36:18 +00:00
|
|
|
##########
|
|
|
|
## main ##
|
|
|
|
##########
|
2023-10-03 19:16:54 +00:00
|
|
|
check_dependencies;
|
2023-10-03 14:40:20 +00:00
|
|
|
mchoice=$(echo -e "$mchos" | dmenu -i -l 4 -p " Screen Capture Menu") # main menu prompt
|
2023-08-08 01:04:48 +00:00
|
|
|
case $mchoice in
|
|
|
|
"$mcho1")
|
2023-10-03 19:16:54 +00:00
|
|
|
mschoice=$(echo -e "$mschos" | dmenu -i -l 9 -p " Screenshot Menu") # screenshot menu prompt
|
|
|
|
case $mschoice in
|
|
|
|
"$mscho1")
|
2023-09-04 17:36:18 +00:00
|
|
|
shot_screen;
|
2023-08-08 01:04:48 +00:00
|
|
|
;;
|
2023-10-03 19:16:54 +00:00
|
|
|
"$mscho2")
|
2023-09-04 17:36:18 +00:00
|
|
|
shot_screen_delay;
|
2023-08-08 01:04:48 +00:00
|
|
|
;;
|
2023-10-03 19:16:54 +00:00
|
|
|
"$mscho3")
|
2023-09-04 17:36:18 +00:00
|
|
|
shot_area;
|
2023-08-08 01:04:48 +00:00
|
|
|
;;
|
2023-10-03 19:16:54 +00:00
|
|
|
"$mscho4")
|
2023-09-04 17:36:18 +00:00
|
|
|
shot_window;
|
2023-08-08 01:04:48 +00:00
|
|
|
;;
|
2023-10-03 19:16:54 +00:00
|
|
|
"$mscho5")
|
2023-08-08 01:04:48 +00:00
|
|
|
exit 0
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
"$mcho2")
|
2023-10-03 19:16:54 +00:00
|
|
|
mschoice=$(echo -e "$mschos" | dmenu -i -l 9 -p " Screencast Menu") # screenshot menu prompt
|
|
|
|
case $mschoice in
|
|
|
|
"$mscho1")
|
|
|
|
rec_screen;
|
|
|
|
;;
|
|
|
|
"$mscho2")
|
|
|
|
rec_screen_delay;
|
|
|
|
;;
|
|
|
|
"$mscho3")
|
|
|
|
#rec_area;
|
|
|
|
notify-send "not implemented yet"
|
|
|
|
;;
|
|
|
|
"$mscho4")
|
|
|
|
#rec_window;
|
|
|
|
notify-send "not implemented yet"
|
|
|
|
;;
|
|
|
|
"$mscho5")
|
|
|
|
exit 0
|
|
|
|
esac
|
2023-10-03 14:40:20 +00:00
|
|
|
;;
|
|
|
|
"$mcho3")
|
|
|
|
stop_recording;
|
|
|
|
;;
|
|
|
|
"$mcho4")
|
|
|
|
exit 0;
|
2023-08-08 01:04:48 +00:00
|
|
|
;;
|
2022-12-20 00:15:21 +00:00
|
|
|
esac
|