2019-08-18 00:25:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-12-21 15:59:25 +00:00
|
|
|
# Simply captures an image.
|
|
|
|
# Also comes with a delay and region selection option.
|
2019-08-18 00:25:29 +00:00
|
|
|
|
|
|
|
# Here are the dependencies needed to successfully
|
2019-08-21 12:34:20 +00:00
|
|
|
# run this script (as of creating this script):
|
|
|
|
# * cat (version 8.31; also unlikely to be missing)
|
|
|
|
# * slop (version 7.4)
|
2019-08-18 00:25:29 +00:00
|
|
|
# * maim (version 5.5.3)
|
|
|
|
# * date (version 8.31)
|
|
|
|
|
|
|
|
# setting up variables for the color
|
|
|
|
red="\u001b[31m"
|
|
|
|
green="\u001b[32m"
|
|
|
|
reset="\u001b[0m"
|
|
|
|
|
|
|
|
function error_cleanup() {
|
2019-08-21 12:34:20 +00:00
|
|
|
# rm "$pic_filepath"
|
2019-08-18 00:25:29 +00:00
|
|
|
printf "$red An error occurred on line $1\n $reset"
|
|
|
|
}
|
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
help_section="
|
|
|
|
Simply captures a screenshot with maim.
|
2019-08-19 01:01:58 +00:00
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
Usage: $0 [-o/--output <OUTPUT_PATH>] [-s/--select]
|
|
|
|
[-d/--delay <SECONDS>] [--help]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--help - show the help section
|
|
|
|
-s, --select - set the screenshot capture to selection mode
|
|
|
|
-d, --delay <SECONDS> - set a delay for the capture
|
|
|
|
(in <SECONDS> seconds)
|
|
|
|
-o, --output <OUTPUT_PATH> - set the output path for the picture;
|
|
|
|
when given no output, the picture will
|
|
|
|
be moved to \$PICTURES_DIRECTORY (or
|
|
|
|
at \$HOME/Pictures if it's missing)
|
|
|
|
"
|
2019-08-19 01:01:58 +00:00
|
|
|
|
2019-08-18 00:25:29 +00:00
|
|
|
# setting up a exit trap in case of error
|
|
|
|
trap 'error_cleanup $LINENO' ERR
|
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
while [[ $# -gt 0 ]]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
-h|--help)
|
|
|
|
echo "$help_section"
|
|
|
|
exit 0;;
|
|
|
|
-d|--delay)
|
|
|
|
DELAY="$2"
|
|
|
|
shift
|
|
|
|
shift;;
|
|
|
|
-s|--select)
|
|
|
|
SELECT=1
|
|
|
|
shift;;
|
|
|
|
-o|--output)
|
|
|
|
OUTPUT="$2"
|
|
|
|
shift
|
|
|
|
shift;;
|
|
|
|
*)
|
|
|
|
shift;;
|
|
|
|
esac
|
|
|
|
done
|
2019-08-18 00:25:29 +00:00
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
set -- "${POSITIONAL[@]}" # restore positional parameters
|
2019-08-18 00:25:29 +00:00
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
if [[ -n "$OUTPUT" ]]; then
|
|
|
|
pic_filepath=$OUTPUT
|
|
|
|
else
|
|
|
|
pic_directory=${PICTURES_DIRECTORY:-"$HOME/Pictures"}
|
|
|
|
date_format=$(date +%F-%H-%M-%S)
|
2019-08-19 01:01:58 +00:00
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
pic_filepath="$pic_directory/$date_format.png"
|
2019-08-19 01:01:58 +00:00
|
|
|
fi
|
2019-08-18 00:25:29 +00:00
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
maim_command="maim $pic_filepath "
|
2019-08-18 00:25:29 +00:00
|
|
|
|
2019-12-21 15:59:25 +00:00
|
|
|
# If selection mode is enabled.
|
2019-08-21 12:34:20 +00:00
|
|
|
if [[ $SELECT -eq 1 ]]; then
|
2019-08-24 13:20:59 +00:00
|
|
|
notify-send "Screenshot capture selection mode" "Select a region to capture the screenshot." --expire-time=1000
|
2019-08-18 00:25:29 +00:00
|
|
|
|
2019-08-24 13:20:59 +00:00
|
|
|
geometry_coordinates=$(slop)
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
notify-send "Screenshot capture cancelled" "Selection mode has been exited."
|
2019-08-21 12:34:20 +00:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
maim_command+="--geometry=$geometry_coordinates "
|
|
|
|
|
2019-08-24 13:20:59 +00:00
|
|
|
if [[ -n "$OUTPUT" ]]; then
|
2019-08-21 12:34:20 +00:00
|
|
|
pic_filepath="$pic_directory/$date_format-$geometry_coordinates.png"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-12-21 15:59:25 +00:00
|
|
|
# Checking if there is a set delay.
|
2019-08-21 12:34:20 +00:00
|
|
|
if [[ $DELAY -gt 0 ]]; then
|
|
|
|
maim_command+="--delay=$DELAY "
|
|
|
|
notify-send "Delayed screenshot" "A delayed screenshot is about to be taken in $DELAY seconds." --expire-time=$(( ($DELAY * 1000) - 1000 ))
|
|
|
|
fi
|
|
|
|
|
2019-09-01 06:23:08 +00:00
|
|
|
$($maim_command)
|
|
|
|
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
notify-send "Screenshot capture failed" "There's something wrong in the capture process. Please try again."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-08-21 12:34:20 +00:00
|
|
|
notify-send "Screenshot taken" "It is saved at $pic_filepath."
|