Created
December 7, 2012 07:46
-
-
Save Saicheg/4231551 to your computer and use it in GitHub Desktop.
Share screenshots on Ubuntu using Dropbox
I've modified mine to work when using it through a keyboard shortcut, as is there were some issues like this:
giblib error: couldn't grab keyboard:Resource temporarily unavailable
It also adds some error handling for when the screenshot/dropbox parts fail, and clears your clipboard like the mac dropbox functionality does (helps avoid pasting whatever was on your clipboard before if for some reason the dropbox bit takes longer than usual).
#!/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"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@worace, just wanted to thank you for the updated version. Works like a charm!