commit 7efba24eacd5ea50cea99ae2660b9c275d4a4527 Author: Bas Dado Date: Mon Sep 4 14:25:33 2023 +0200 Initial commit: basic scripting, working under KDE Wayland diff --git a/README.md b/README.md new file mode 100644 index 0000000..4277a5d --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Screenshot taker tool +Based on this: https://superuser.com/questions/1594667/how-can-i-make-a-screenshot-log-on-linux + + +## Usage +Copy the files in systemd to: `~/.config/systemd/user/` +Modify the paths in them so they point to wherever this repo is. +Run: +```bash +systemctl --user start screenshot.service screenshot.timer +``` \ No newline at end of file diff --git a/screenshot.sh b/screenshot.sh new file mode 100755 index 0000000..a48aa60 --- /dev/null +++ b/screenshot.sh @@ -0,0 +1,48 @@ +#!/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 "

`date +%H:%M:%S`
$WINDOW_TITLE

" >> $DIR/`date +%Y-%m-%d`-$PREFIX.html +fi diff --git a/systemd/screenshot.service b/systemd/screenshot.service new file mode 100644 index 0000000..c533642 --- /dev/null +++ b/systemd/screenshot.service @@ -0,0 +1,8 @@ +[Unit] +Description=Take screenshot +DefaultDependencies=no +After=local-fs.target time-set.target + +[Service] +Type=oneshot +ExecStart=/home/immortaly007/Scripts/screener/screenshot.sh \ No newline at end of file diff --git a/systemd/screenshot.timer b/systemd/screenshot.timer new file mode 100644 index 0000000..3584b05 --- /dev/null +++ b/systemd/screenshot.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Take screenshot every 1 minutes with random delay + +[Timer] +OnCalendar=*:00/1:00 +# RandomizedDelaySec=3m +AccuracySec=1s +Persistent=false + +[Install] +WantedBy=default.target \ No newline at end of file