#!/bin/sh
n=$1
output=$2
tmpdir=/tmp/sent-screenshot.$$
(umask 077 && mkdir $tmpdir) || exit 1
xdotool search --class sent windowactivate --sync windowsize 800 600
i=1
while [[ i -le $n ]]; do
    import -window "$(xdotool getwindowfocus -f)" $tmpdir/$(printf "%04d" $i).png
    xdotool search --class sent key --window %@ space
    i=$((i+1))
done
convert $tmpdir/*.png $2
