Skip to content

Instantly share code, notes, and snippets.

@johnl
Created June 11, 2013 11:17
Show Gist options
  • Save johnl/5756118 to your computer and use it in GitHub Desktop.
Save johnl/5756118 to your computer and use it in GitHub Desktop.
high speed screenshot and upload utility
#!/bin/bash
#
# Copyright 2013 John Leach <john@johnleach.co.uk>
#
# Distributed under terms of the MIT license
#
# Takes a screeshot using scrot and uploads it via scp and sticks the
# url on the clipboard as quickly as possible.
#
# For speed, it cheats and puts the url on the clipboard *before*
# uploading.
#
# Requires the scrot screenshot tool, scp, sha256sum, xclip and
# notify-send. Rquires ruby too, but a bit unecessarily.
#
set -e
URLBASE="http://example.com/screenshots"
SCPURL="user@example.com:www/screenshots"
if [ -d /dev/shm ] ; then
TMPDIR="/dev/shm"
else
TMPDIR=$TMP
fi
# FIXME: unsafe, use mktemp instead
TMPFILE="$TMPDIR/scrot-${USER}-`date +"%s"`.png"
sleep 0.1 # needed due to a bug in gnome-shell with keyboard focus
scrot -s $TMPFILE
CSUM=`sha256sum $TMPFILE | ruby -e 'puts STDIN.read.to_i(16).to_s(36)'`
FILENAME=`date +%Y%m%d`-${CSUM}.png
URL=$URLBASE/${FILENAME}
echo -e "`date`:\t$TMPFILE\t$URL" >> $HOME/screenshot.log
echo $URL | xclip
scp $TMPFILE $SCPURL/${FILENAME} &&
/usr/bin/notify-send -t 2000 -u low "Screenshot uploaded successfully" &&
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment