Last active
May 15, 2016 11:49
-
-
Save dhornbein/5030744 to your computer and use it in GitHub Desktop.
Bash script that captures a screenshot, saves screenshot, optionally uploads it to Imgur.com, and injects URL to clipboard and meta data of saved file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# By Drew Hornbein @ http://dhornbein.com | |
# | |
# Modified from:https://github.com/Sirupsen/sirupsen.github.com/blob/master/static/misc/shoot | |
# By Sirupsen @ http://sirupsen.dk | |
# | |
# Description: Very simple script to make you | |
# select a region of your screen, which will be captured, saved, and | |
# then uploaded. The URL will then be injected into your clipboard. | |
# | |
# Dependencies: | |
# | |
# Imgur Bash Upload Script (http://imgur.com/tools/imgurbash.sh) | |
# Comment: Must be in path (see below) with the name "imgur" (not imgur.sh) | |
# | |
# Scrot | |
# Comment: Scrot is what takes the actual screenshot. | |
# | |
# Xclip | |
# Comment: Xclip is what makes the script able to inject the direct url | |
# into your clipboard. | |
# | |
# libnotify* | |
# Comment: Will notify you whenever the direct URL is in the clipboard | |
# | |
# Installation: | |
# | |
# Move the file to a local bin. And put the path of this bin, into | |
# your path. (See: www.troubleshooters.com/linux/prepostpath.htm) | |
# | |
# From then on, you can either activate it via your terminal, or via | |
# your window manager or similar, so you can bind it to a keycombination. | |
# | |
function uploadImage { | |
curl -s -F "image=@$1" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml | grep -E -o "<original_image>(.)*</original_image>" | grep -E -o "http://i.imgur.com/[^<]*" | |
} | |
path=~/sync/screenshots/ | |
name="`date "+%F_%R:%S"`_`hostname`_ss.png" | |
scrot -s $path$name | |
OUT=$? | |
if [ $OUT -eq 0 ] | |
then | |
# asks if you want to upload | |
if zenity --window-icon=$path$name --title="Screenshot grabbed" --question --text="Upload $name to Imgur?"; then | |
url=$(uploadImage $path$name) | |
echo $url | xclip -selection c | |
notify-send -i $path$name "Image saved & Imgur link in clipboard" "Url: $url \n $path$name" | |
convert $path$name -set Imgur "$url" $path$name #adds the Imgru url to the file's metadata | |
else | |
echo $path$name | xclip -selection c | |
notify-send -i $path$name "$name saved: path in clipboard" "$path$name" | |
fi | |
else | |
notify-send "Screenshot failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice