Files
minute-screenshot-linux/screenshot.sh

49 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/bash
DIR="/home/immortaly007/screenshot-log"
FORMAT="png"
SIMILARITY_DELETE_TRESHOLD=100
HTML_THUMB_WIDTH=200
SCALE="50%"
DAY=`date +%Y-%m-%d`
TIME=`date +%H.%M.%S.%3N`
mkdir -p $DIR/$DAY
SCR_NEW="$DIR/$DAY/$TIME.$FORMAT"
SCR_LAST=`ls -t $DIR/$DAY/*.png | head -n1`
# do a screenshot
if [ "$DESKTOP_SESSION" = "plasmawayland" ]
then
spectacle -bn -o $SCR_NEW
else
import -window root $SCR_NEW
fi
#requires ImageMagick
DISTANCE=`compare -metric MAE $SCR_LAST $SCR_NEW NULL: 2>&1`
echo $DISTANCE
# ImageMagick outputs something like "21.8357 (0.218357)"; we only want to use the first number for the comparison below, so we use cut to get just that
DISTANCE=`echo $DISTANCE | cut -d " " -f1 -`
if [ "$DISTANCE" = "inf" ]
then
DISTANCE=1000
fi
echo $DISTANCE between $SCR_LAST and $SCR_NEW
IS_SIMILAR=`echo "$DISTANCE < $SIMILARITY_DELETE_TRESHOLD" | bc`
if [ "$IS_SIMILAR" = "1" ]
then
rm $SCR_NEW
echo "`date`: Distance = $DISTANCE; too similar; RM $SCR_NEW"
# echo "`date` RM" >> $DIR/$DAY/log-.log
else
mogrify -scale $SCALE $SCR_LAST
# Ensure that the new file is still seen as the most recent one
FUTURE=`date +%Y%m%d%H%M.%S -d "+1 second"`
touch -t $FUTURE "$SCR_NEW"
# echo "<p>`date +%H:%M:%S` <a href=\"$SCR_NEW\"><img width=\"$HTML_THUMB_WIDTH\" src=\"$SCR_NEW\" /></a> <br />$WINDOW_TITLE </p>" >> $DIR/`date +%Y-%m-%d`-$PREFIX.html
fi