Skip to content

Instantly share code, notes, and snippets.

@maximilize
Last active December 19, 2015 17:39
Show Gist options
  • Save maximilize/5992807 to your computer and use it in GitHub Desktop.
Save maximilize/5992807 to your computer and use it in GitHub Desktop.
Screeny - a simple screenshot upload tool. It copies the image url to the clipboard.
#!/bin/bash -e
# Upload script with cool notify icons.
# Url of the image is copied to clipboard.
#
# INSTALL
# 1. Install dependencies:
# sudo apt-get install curl notify-send scrot xclip
#
# 2. Install the script
# sudo wget -O /usr/bin/screeny https://gist.github.com/max0d41/5992783
# sudo chmod 755 /usr/bin/screeny
#
# USAGE
#
# The arguments are passed directly to scrot, so try --help if you don't know what to do.
# You can replace the upload function with whatever you want. It have to print the result url to stdout.
#
# To add shortcuts in xfce (xubuntu) go to Settings -> Keyboard -> Shortcuts and add items like:
#
# /usr/bin/screeny
# Captures the whole screen, shortcut key <Print>
#
# /usr/bin/screeny -u
# Captures the window that have the focus, shortcut key <Print>+<Primary>
#
# /usr/bin/screeny -s
# Captures a selectable area, shortcut key <Print>+<Alt> (this does not work for me on my laptop, i have to use Primary+Alt+s)
#
# NOTES
# Scrot has a bug when this script is called by a shortcut so we have to sleep for a short time.
function upload {
curl -s -F "image=@$1" -F "key=486690f872c678126a2c09a9e196ce1b" https://imgur.com/api/upload.xml | sed -r "s/^.*<original_image>(.*)<\/original_image>.*$/\1/" | grep "^http"
}
function die {
notify-send -t 3000 -i face-angry "screeny" "$1"
rm -f "$TMP"
exit 1
}
TMP="/tmp/screeny.png"
[ "$1" == "-s" ] && sleep 0.25 && notify-send -t 1500 -i edit-find "screeny" "Select a screen area"
scrot $@ "$TMP" || die "Error taking the screenshot"
notify-send -t 2000 -i document-send "screeny" "Upload started"
URL=$(upload "$TMP" || die "Upload failed")
rm -f "$TMP"
echo "$URL" | xclip -selection p
echo "$URL" | xclip -selection c
notify-send -t 2000 -i face-smile "screeny" "Upload done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment