Skip to content

Instantly share code, notes, and snippets.

@seanbeaton
Created December 15, 2018 01:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seanbeaton/25aa29aa5089c22e031043e344f9ae9f to your computer and use it in GitHub Desktop.
Save seanbeaton/25aa29aa5089c22e031043e344f9ae9f to your computer and use it in GitHub Desktop.
create-screenshot-scrot
#!/bin/bash
# Clear clipboard (can't be pasting any passwords if we try to paste too fast).
echo "" | xclip -selection clipboard
mkdir -p $HOME/Dropbox/shots/
TSTAMP=`date '+%Y-%m-%d-%H-%M-%S'`
IMAGEPATH=$HOME/Dropbox/shots/Screenshot-$TSTAMP.png
# Not waiting a bit will cause errors when using keyboard shortcuts
# to run the script, like the one below:
#
# giblib error: couldn't grab keyboard:Resource temporarily unavailable
#
# To avoid this, we just sleep for a bit.
sleep 0.2 && scrot "$IMAGEPATH" -s 2>>~/screenshot-select-errors
if [ $? -ne 0 ] ; then
echo "Command failed, unable to create screenshot. See log in ~/screenshot-select-errors"
notify-send "Screenshot failed" "Unable to create screenshot. See log in ~/screenshot-select-errors"
exit
fi
DROPBOX_LINK=`dropbox sharelink $IMAGEPATH`
# Dropbox doesn't return a non-zero exit code when it can't get a link.
# Instead, we'll see if the result is a link.
if [[ $DROPBOX_LINK != http* ]] ; then
echo "Command failed, $DROPBOX_LINK"
notify-send "Screenshot failed" "$DROPBOX_LINK"
exit
fi
echo $DROPBOX_LINK | xclip -selection clipboard
echo "Created screenshot, share link: $DROPBOX_LINK"
notify-send "Screenshot Saved" "$DROPBOX_LINK"
@xazax
Copy link

xazax commented Jan 3, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment