Trey Hunner

I help developers level-up their Python skills

Hire Me For Training

Sharing Screenshots in Linux

| Comments

I have been using Github Issues recently and loving its simplicity.  Unfortunately, I’ve found that I often need to upload screenshots to demonstrate bugs and Issues does not support file uploads.  There are Windows and Mac applications that solve this problem by capturing a screenshot, uploading it, and copying a URL to access the screenshot to the clipboard.

I did not find any Linux applications that will capture/upload a screenshot and copy the URL but I discovered a thread in the Dropbox forums with a script that does just that.  I added comments to the script, changed the variable names, removed the need for a temporary file, and added a notify-send call as a visual cue (should work on Ubuntu).  I have the script mapped to Ctrl-PrtScrn in Ubuntu.

#!/bin/sh
# Ubuntu-specific modification of http://wiki.dropbox.com/TipsAndTricks/ShareScreenshots

# Change these
DB_USER_ID=YOURDBUSERID
BITLY_USERNAME=YOURBITLYUSERNAME
BITLY_API_KEY=YOURBITLYKEYHERE
DROPBOX_PUBLIC_DIR=~/Dropbox/Public
SCREENSHOT_DIR=screenshots

CAPTURE_DELAY=0
PICTURE_QUALITY=50
FILE_EXTENSION=png
TIME=$(date +%Y%m%d%H%M%S)
FILENAME=$TIME.$FILE_EXTENSION

# Move to the directory where screenshots will be stored
mkdir -p $DROPBOX_PUBLIC_DIR/$SCREENSHOT_DIR
cd $DROPBOX_PUBLIC_DIR/$SCREENSHOT_DIR

# Take screenshot and save in screenshot directory
scrot -d $CAPTURE_DELAY -q $PICTURE_QUALITY $FILENAME

# Get Dropbox public URL for screenshot
DB_URL="http://dl.dropbox.com/u/$DB_USER_ID/$SCREENSHOT_DIR/$FILENAME"

# Get bit.ly shortened URL for Dropbox URL
ESCAPED_DB_URL="$(echo $DB_URL | sed 's,:,%3A,g;s,/,%2F,g')"
BITLY_API_CALL="http://api.bit.ly/v3/shorten?login=$BITLY_USERNAME&apiKey=$BITLY_API_KEY&longUrl=$ESCAPED_DB_URL&format=txt"
SHORT_URL=$(curl -s -S $BITLY_API_CALL)

# Copy shortened URL to clipboard
echo $SHORT_URL | xclip -sel clip

# Display message to user (requires libnotify)
notify-send "Screenshot added" "Screenshot link copied to clipboard: $SHORT_URL"

Comments

Write more Pythonic code

Need to fill-in gaps in your Python skills? I send regular emails designed to do just that.