Screenshot + Upload with one keypress

Posted on 15th November, 2010 | Tagged:

I wanted to share a screenshot with somebody online the otherday, but the routine that came to mind went like this ..

  1. Load the gimp
  2. Click several buttons
  3. Switch to the desktop I want to screenshot
  4. Save the image to disk
  5. Copy the image to my web server
  6. Test the URL
  7. .. and finally pasting the URL to the person

So, I searched aptitude for an alternative

apt-cache search screenshot | grep screen

and shutter was able to eliminate a few of the above steps, but I thought that at some point I should stop being lazy and write a script.

My script will:

  1. Take a screenshot with a generated filename
  2. Upload the screenshot to my webserver
  3. Copy the URL for the screenshot to the clipboard
  4. Be bound to a keyboard shortcut in awesome

So that when I want to share a screen with somebody I only have to press a button, wait a few seconds then paste the URL.

My script

#/bin/bash
FNAME=`uname -n`-`date  +%Y%m%d%H%M%S`.png
SSH=daniel@www.dantleech.com:/home/daniel/screenshots
URL=http://www.dantleech.com/screenshots/

import -window root /tmp/$FNAME
scp /tmp/$FNAME $SSH
rm /tmp/$FNAME

echo $URL$FNAME | xclip -i -selection primary

So it:

  1. Defines some configuration variables
  2. Takes the screenshot using import
  3. Copies the screenshot to the server using scp
  4. Removes the temporary file
  5. Pipes the URL into the X clipboard using xclip

Integrating it into the Awesome WM

I added a keybinding in the rc.lua configuration file which calls the following function:

function screenshot()
  os.execute("/home/daniel/scripts/screenshot.sh")
  naughty.notify({title = "Screenshot taken"
  , text = "URL copied to clipboard"
  , timeout = 5
  , position = "top_right"
  , fg = beautiful.fg_focus
  , bg = beautiful.bg_focus
  })
end

So it will execute my script and, when it has finished, awesome will notify me with a little popup in the top-right hand corner. Pretty neat I think!

Example

Example showing scripts

Comments

Be the first to leave a comment.

Post new comment


type "i hate spam" in UPPER CASE

Tags

10 Latest Items