Skip to content

Instantly share code, notes, and snippets.

@foozmeat foozmeat/timed_capture.sh
Last active Dec 11, 2015

Embed
What would you like to do?
A bash script to take screenshot every 60 seconds and then add a timestamp to it. Useful for creating time-lapse videos.
#!/bin/sh
# Help from http://dptnt.com/2009/08/add-date-time-stamp-to-jpeg-photos-using-free-software-mac-linux-nix-edition/
# install the LCD font - http://www.dafont.com/digital-7.font
# install imagemagick via homebrew
# Install Time Lapse Assembler to make the movie - http://www.dayofthenewdan.com/projects/time-lapse-assembler-1/
set -e
font="$HOME/Library/Fonts/digital-7 (mono).ttf"
outputfolder="$HOME/Downloads/caps"
# Format is x,y,width,height. Origin is the upper-left corner
rect="403,94,1061,1026"
delay=2
fontFill="black"
################################################################
mkdir -p ${outputfolder}
while [ 1 ];do
date=$(date +%d\-%m\-%Y\_%H.%M.%S)
file="/tmp/${date}.png"
screencapture -t png -R${rect} -x ${file}
output="${outputfolder}/${date}.png"
# Get the file dimension
dim=$(identify -format "%w %h" "$file")
width=${dim%% *}
height=${dim#* }
# file date
MODDATE=$(stat -f "%Sm" $file)
# Decide the font size automatically
if [ $width -ge $height ]
then
pointsize=$(($width/30))
else
pointsize=$(($height/30))
fi
echo "Writing file: $output"
convert "$file" -gravity SouthEast -font "$font" -pointsize $pointsize -fill ${fontFill} -annotate +$pointsize+$pointsize "${MODDATE}" "$output"
rm ${file}
sleep ${delay}
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.