#!/bin/sh # takes a screenshot of the currently focused window every n seconds # and saves it in a directory. # usage: take-screenshots-in-intervals [interval destination_dir] # dependencies: scrot image_width=400 interval=1000 destination_root="$HOME/interval-screenhots" if test "$1" then interval="$1" fi if test "$2" then destination_root="$2" fi echo "destination: $destination_root, interval: ${interval}s" day_seconds() { now=$(date -u '+%s') midnight=$(date -u -d 'today 00:00:00' '+%s') echo $((now - midnight)) } scale_image() { width=$1 path=$2 temp_path=$(dirname "$path")/scaled_$(basename "$path") gm convert -size "$width>x" "$path" -auto-orient -resize "${width}x${width}>" "+profile" "*" "$temp_path" && mv "$temp_path" "$path" } while true; do # the date may change while this loop is running date=$(date -u +%Y-%m-%d.%j) directory="$destination_root/$date" mkdir -p $directory full_path="$directory/$(day_seconds).jpg" scrot --focused --quality 85 "$full_path" && scale_image $image_width "$full_path" sleep $interval done