Open Screenshotting

There are a number of services out there that allow you to take a screenshot and upload it to a website. All of these tools that I have seen(I didn't look, at all) used have involved a proprietary service and uploading your images to someone else's hosting.

That isn't good enough for me, I needed an open tool I could use anywhere (FreeBSD support) with the ability to drop the resulting png into a directory on a webserver I control.

Here is my tool to solve this problem, screenshot. Screenshot can capture either the entire window or offer a picker to grab a certain area. I used import from ImageMagick to handle the capturing and some glue to upload the image. There is another option to open the image with feh if required.

$ screenshot open
$ screenshot upload
$ screenshot pick upload

The script also dumps file names and url into a log file, this makes it easy to track down the last taken screen shots. I have some awk magic to pull out the last url and throw it onto my clipboard.

#!/bin/sh

shotdir=$HOME/screenshots
site="mysite.me"
uploaddir="webdir/screenshots/"

if [ ! -d $shotdir ]; then
    mkdir $shotdir
fi

one=`word`
two=`word`

word=$one-$two.png
file=$shotdir/$word
name=`basename $file`
url=$site/screenshots/$name

pick=false
open=false
upload=false

for var in "$@"
do
    if [ "$var" = "pick" ]; then
        pick=true
        continue;
    fi

    if [ "$var" = "upload" ]; then
        upload=true
        continue;
    fi

    if [ "$var" = "open" ]; then
        open=true
        continue;
    fi
    file=$var
done

echo "File:" $file

echo $file "http://"$url >> $shotdir/screenshot.log

if $pick; then
    import $file;
else
    import -window root $file;
fi

if $upload; then
    scp $file $site:$uploaddir/$name
fi

if $open; then
    feh $file
fi

I use another shell script to generate a random word. This script uses my local system dictionary, /dev/random and some glue to get a random word. The glue uses three bytes read from /dev/random and uses od to format those bytes into something useful. I then use sed to seek to the line in the dictionary to get the word.

#!/bin/sh

words="/usr/share/dict/words"

num=`od -An -N3 -i /dev/random`

line=$(($num % `wc -l < $words`))

word=`sed -n "$line"p $words`

echo -n $word