Skip to content

Instantly share code, notes, and snippets.

@Saicheg
Created December 7, 2012 07:46
Show Gist options
  • Save Saicheg/4231551 to your computer and use it in GitHub Desktop.
Save Saicheg/4231551 to your computer and use it in GitHub Desktop.
Share screenshots on Ubuntu using Dropbox
#!/bin/bash
################
# Description:
# This script will take screenshot of your desktop
# or only active window ( running with -u param ),
# copy it to /Dropbox/Public/share/ with uniq name
# and save path to clipboard
#################
# Requirements:
# Dropbox
# scrot
# xclip
#################
TSTAMP=`date +%s`
IMAGEPATH=~/Dropbox/Public/share/Screenshot-$TSTAMP.png
scrot $1 $IMAGEPATH
dropbox puburl $IMAGEPATH | xclip
@seanbeaton
Copy link

@worace, just wanted to thank you for the updated version. Works like a charm!

@seanbeaton
Copy link

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