Created
December 15, 2018 01:29
-
-
Save seanbeaton/25aa29aa5089c22e031043e344f9ae9f to your computer and use it in GitHub Desktop.
create-screenshot-scrot
This file contains 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 | |
# 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
Thank you!