#!/bin/bash -e
# screenie is a small script that is designed to instantly take a screenshot of your current desktop, upload the screenshot to the Internet, grab the file's URL and compact it down via the bit.ly (http://www.bit.ly) URL shortening service. There are three external commandline dependencies, programs which should be available in your distro's repositories:
#
# 1. curl, 2. scrot, and 3. xclip
#
# You are free to alter and redistrbute this script as you see fit, although I would ask that you leave this attribution in place. Any queries or comments should be send to my email: mark@bhalash.com or my Twitter account: @bhalash. If you don't already have Dropbox installed, you can get it (and help me out with more space!) through this link:
#
# https://www.dropbox.com/referrals/NTQxNDQ5MTk5
#
# There are three very important variables that you *must* change:
#
# 1. DBUSER - your Dropbox user ID. You can acquire this by right-clicking on any item in your Public Dropbox folder and copying the public sharing link. The 7-digit string of numbers, $FOO, in "http://dl.dropbox.com/u/$FOO/file.jpg" is your UID.
# 2. BITLYUSER - Your bit.ly user name. This should be self-explanatory.
# 3. BITLYKEY - Your bit.ly API key. It can be found at http://bit.ly/a/account
DBUSER=CHANGEME1 # Your Dropbox UID.
BITLYUSER=CHANGEME2 # Your bit.ly login name - comment out to disable URL shortening
BITLYKEY=CHANGEME3 #Your bit.ly API key
TIME=$(date +%Y%m%d%H%M%S) # File name format is YYYYMMDDHHMMSS.jpg
DBDIR1=~/Dropbox/Public # You shouldn't need to change this. Ever.
SSDIR2=screenshots # Ditto. Just make sure it stays in your Public folder.
[ -d $DBDIR1/$SSDIR2 ] || mkdir $DBDIR1/$SSDIR2
cd $DBDIR1/$SSDIR2
SSHOTFILE=$TIME.jpg
DBURL="http://dl.dropbox.com/u/$DBUSER/$SSDIR2/$SSHOTFILE"
scrot -d 0 -q 100 $SSHOTFILE
[ -z "$BITLYUSER" ] && echo "$DBURL" | xclip -sel clip && exit 0
BITLYURL="http://api.bit.ly/v3/shorten"
curl="curl -s -S -G $BITLYURL"
params="-d login=$BITLYUSER -d apiKey=$BITLYKEY -d format=txt"
params="$params --data-urlencode longUrl=$DBURL"
$curl $params | xclip -sel clip
exit $?