Skip to content

Instantly share code, notes, and snippets.

@mattdconnell
Created April 17, 2017 16:56
Show Gist options
  • Save mattdconnell/7a862d542a06f59302f69dbec634e693 to your computer and use it in GitHub Desktop.
Save mattdconnell/7a862d542a06f59302f69dbec634e693 to your computer and use it in GitHub Desktop.
Puush + scrot
#!/bin/sh
# The message that the user will be sent.
MESSAGE=""
# API key definition.
API_KEY_FILE="/home/$USER/.puush.api"
# Read in the user's API key
if [ -f $API_KEY_FILE ]
then
source $API_KEY_FILE
# Make sure the key is defined
if [ -z "$PUUSH_API_KEY" ]
then
MESSAGE="Please set the variable PUUSH_API_KEY in $API_KEY_FILE."
notify-send "Puush failed." "$MESSAGE"
exit 1
fi
else
MESSAGE="No API key file found at $API_KEY_FILE ...exiting."
notify-send "Puush failed." "$MESSAGE"
exit 1
fi
# Timestamp for filename
STAMP=`date +%s`
# Temp file for screenshot
TMPFILE="/tmp/shot.png"
# If we're saving a local copy, do it here.
SAVE_DIR="/home/$USER/Pictures/puush/"
# Take the actual screenshot.
# This is where the user gets the cross and can select a portion of the screen
scrot -s $TMPFILE
# If the SAVE_DIR is defined, save the file.
if [ -d $SAVE_DIR ]
then
cp $TMPFILE $SAVE_DIR/$STAMP.png
MESSAGE="$MESSAGE\n\nFile saved to $SAVE_DIR"
else
MESSAGE="$MESSAGE\n\nFile not saved since $SAVE_DIR doesn't exist."
fi
# Make the curl request to puush's API,
# pass along the API key,
# post the screenshot file,
# strip garbage from the result of the curl request,
# and put it on the user's clipboard
curl -s "https://puush.me/api/up" -# -F "k=$PUUSH_API_KEY" -F "z=poop" -F "f=@$TMPFILE" | sed -E 's/^.+,(.+),.+,.+$/\1\n/' | xclip -selection c
MESSAGE="Success. URL copied to clipboard."
# Finally send the message
notify-send "Puushed!" "$MESSAGE"
# Exit nicely.
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment