Skip to content

Instantly share code, notes, and snippets.

@katanacrimson
Created April 24, 2012 16:25
Show Gist options
  • Save katanacrimson/2481186 to your computer and use it in GitHub Desktop.
Save katanacrimson/2481186 to your computer and use it in GitHub Desktop.
Quick and dirty shell script for getting screenshots quickly taken and uploaded.
#!/bin/bash
#
# Local push to own server
#
# Requires:
# - remote webserver (best used w/userdirs)
# - local package "scrot"
# - local package "xclip"
# - local package "pngcrush"
# - iq > 20
# - linux
# - internet connection...unless you do it all via LAN. why would you do it all over LAN? are you some kind of introverted, lonely, angsty sadist?
#
# If you want it hooked up to a hotkey, figure out how to do that in your distro of choice.
#
TEMP_DIR="/tmp/"
LOCAL_DIR="/home/katana/push/"
REMOTE_SCP="katana@sabros:/home/katana/public_html/push/"
WEB_URL_BASE="http://codebite.net/~katana/push/"
FILENAME=`date +%s`"-${RANDOM}.png"
echo screenshot saving to "${LOCAL_DIR}${FILENAME}"
scrot -d 0 "${TEMP_DIR}${FILENAME}"
if [ $? -ne 0 ]
then
notify-send -u critical "Screenshot failed"
else
pngcrush -q "${TEMP_DIR}${FILENAME}" "${LOCAL_DIR}${FILENAME}"
WEB_FILENAME=`md5sum "${LOCAL_DIR}${FILENAME}" | sed -e 's/\([^ ]*\) \(.*\(\..*\)\)$/\1\3/'`
scp "${LOCAL_DIR}${FILENAME}" "${REMOTE_SCP}${WEB_FILENAME}"
echo "file uploaded to ${REMOTE_SCP}${WEB_FILENAME}"
echo "upload viewable at ${WEB_URL_BASE}${WEB_FILENAME}"
echo "${WEB_URL_BASE}${WEB_FILENAME}" | xclip -selection clipboard
notify-send "Image uploaded, link copied to clipboard"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment