You are Here: Articles » A Script to Automatically Upload Screenshots to the Web from Ubuntu

A Script to Automatically Upload Screenshots to the Web from Ubuntu

When the print screen button is pressed, take a screenshot, upload it to the specified location with FTP and copy the URL to the clipboard.

Tagged with Software, Open Source, Ubuntu and Graphics
Posted on 22/11/08 by Paul Herron

To show what's on my screen to someone who isn't with me, the easiest solution is usually to grab a screenshot, upload it to the Web and send out the URL. On Windows, I've used the basic but functional SnapTake to help with that, and there are various other desktop- and web-based solutions.

Although I coulnd't find any one Ubuntu package to do the same thing, a few programs combined could, and these were easily patched together with a small bash script.

Dependencies

We'll need a few packages to make this work, so from the terminal, issue the following command:

  1. sudo apt-get install scrot ncftp xclip compizconfig-settings-manager

scrot will take care of grabbing the screenshot and saving it locally. ncftp will let us take that file and upload it with FTP. xclip will take the URL of the uploaded file and insert it into the clipboard. CompizConfig Settings Manager will let us easily bind this whole process to the Print Screen key.

Making the Script

The script is just some variable declarations and a few commands:

  1. #!/bin/bash
  2.  
  3. # Declare FTP access details
  4. FTPSERVER=ftp.example.com
  5. USERNAME=screenshots@example.com
  6. PASSWORD=password
  7. # Declare the local directory to which the file should be saved.
  8. dir=~/screenshots
  9. # Declare a filename. I used a timestamp as a simple way to get a unique filename.
  10. filename=myscreenshot-$(date +%Y-%m-%d_%H%M%S)
  11. # Declare the URL of the directory to which the file will be uploaded.
  12. url=http://example.com/screenshots/
  13.  
  14. # After a delay of 2 seconds, save a PNG screenshot.
  15. scrot -d 2 -q 1  "$dir/$filename.png"
  16. # Upload the screenshot.
  17. ncftpput -u $USERNAME -p $PASSWORD   $FTPSERVER$dir/$filename.png
  18. # Copy the URL of the uploaded screenshot to the clipboard.
  19. echo "$url$filename.png" | xclip -selection c
  20.  
  21. exit

We could just put the script in /usr/bin, but it's useful to create a personalised bin in the home directory, ~/bin. This way, all of your personal scripts can be backed up along with your other documents. Saving the file as ~/bin/shoot is therefore a good way to go.

If they aren't there already, you might need to add the following lines to your ~/.profile or ~/.bash_profile file. This will let us simply call shoot from the terminal, rather than specifying the full path to the script.

  1. # set PATH so it includes user's private bin if it exists
  2. if [ -d "$HOME/bin" ] ; then
  3.     PATH="$HOME/bin:$PATH"
  4. fi

The script should now work if we call shoot from the terminal.

Binding the Script to the Print Screen Key

Handily, we can use Compiz's built-in key binding management to call shoot when the Print Screen button is pressed. CCSM gives us an interface for this. Just select General, then General Options, then choose the Commands tab. Under Screenshot commands, enter shoot in the Sceenshot command line box.

Enter 'shoot' in the box labelled 'Sceenshot command line'.

Improvements

This script has just the bare minimum functionality, but does just what I need. Some improvements could be handy, though:

  • Allow individual windows to be captured, rather than just the entire screen.
  • Include error detection and messages. At the moment, the script just fails silently in the background if something goes wrong.
  • Give a prompt when the file has been uploaded. The prompt could offer functionality such as copying the URL to the clipboard as options.

I'll have a look at those when I get time.

Comments

christian louboutin outlet wrote on 1/11/11:

I find myself passionately concerning this and even appreciate knowing a little more about the following subject matter. Whenever you can, just like you attain abilities, will you thought process posting yuor web blog to comprehend information and facts? This can be very used by my family.

Northface jackets wrote on 9/11/11:

He converted to Islam and changed his name to Muhammad Ali. North Face Apex Bionic Jackets After he refused to be drafted into the United States Army during the Vietnam War, he was stripped of his title and did not fight again for 3 ? years.

office2010key wrote on 16/11/11:

The Microsoft office 2011 users can Office 2010 work more efficiently with the Microsoft Office 2010 simple and intuitive Download Office 2010 user interface new graphical MS Office 2010 menus and a familiar Office 2010 Key experience provide the Office 2010 Download tools you need to plan and Office 2010 Professional manage your project. And the Microsoft Office 2010 Download tabs and contextual menu buy microsoft office 2010 groupings reveal powerful features, Windows 7 making it easier to get Microsoft Windows 7 started and realize results Win 7. Simply be more productive Download Windows 7 by choosing your own menu Buy Windows 7 options, quick access Office 2007 toolbar settings and Microsoft Office 2007 setting defaults.Enhanced copy Office 2007 Download and paste makes it easy to Office 2007 Professional share information effectively MS Office 2007 with other Office 2007 Key applications while retaining buy microsoft office 2007 formatting. And the added columns Download Office 2007 dynamically by entering Microsoft Office 2007 Professional data without having to first select purchase microsoft office 2007 the data type.

http://softwarestockss.blogspot.com

http://software-stocks.com

designer rolex watches wrote on 9/12/11:

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

Designer designer rolex watches are a quite laid-back nonetheless on the very same occasion a remarkably significant moderate of feelings as well as persona. To lessen the actual long term history limited, without having communicating a phrase, this introduces someone or even woman with the some other party. For that reason, it is really an outstanding decision to be a gift.

discount north face jackets wrote on 16/12/11:

Not because the north face are not afraid of light, <a href="http://www.discountnorthfaces.net/">discount north face jackets</a> but because the north face did not look directly at their bird gold black. The general audience does not know black gold is normal, the north face when they However, the thing is seen, so they just fly out of sight immediately turned to the side.

discount north face jackets wrote on 16/12/11:

Not because the north face are not afraid of light, discount north face jackets but because the north face did not look directly at their bird gold black. The general audience does not know black gold is normal, the north face when they However, the thing is seen, so they just fly out of sight immediately turned to the side.

cartier ballon bleu watch wrote on 24/12/11:

OMG!!!.. That is a great interesting article. Thanks for sharing.

[url=http://www.watcheslake.com/luxury-cartier-ballon-bleu-de-cartier-replica-cb399.html]cartier ballon bleu watch[/url]

cartier ballon bleu watch wrote on 24/12/11:

OMG!!!.. That is a great interesting article. Thanks for sharing.

penny wrote on 27/12/11:

How much depends on personal taste and pepper set, a quarter cup of the new Romano or Parmesan cheese made, GHD Pink Limited Edition half a large potato as far as possible organically grown potatoes, GHD Precious Gift Set certainly are a luscious swimming pool irons supplementary substance unequal product reaches excessively higher temperatures quickly. The main aims are bleaching your wild GHD Rare shortly after Christmas. Sprite ghd pink straighteners beneficial present founded executed concerning the notion. The package deal also consists of two warm biopsy forceps as well as a pink "style type ghd white straighteners. Ghd wild hair straightener affordable right here will make your desire a reality, curls and straight. The ghd dark limited edition also comes with a stylish black case that can also be used to store and protect the straightener when it is not in use. The pink ghd straighteners is a wonderful product, that offer customers the absolute best in hair styling and straightening.This means that if a ghd mini hair straighteners is to break within two years after purchase,replacement straightener.

north face outlet store wrote on 30/12/11:

Earth of door connection of is Earth of mother of Hou Garden, but this so-called of garden, actually is a area quite does not small of land. in this tablets regional of are <a href="http://www.northfacestores.net/">north face outlet store</a>  just has a area quite broad of Lake, will the north face were before this Lake of water are pumping to Earth of mother of that Garden in of Lake in the words, at most is let that Lake of water level rose a one or two m only, this on around of environment due to the no too large effect, the North Face of the earth mother should not mind. even if she is really unhappy, the north face is to pour water out somewhere.

4234 wrote on 2/1/12:

Today's start off to really feel slightly bit like Groundhog Day, louis vuitton sale is not it? A few hours ago, we brought to you a story about Louis Vuitton suing a media organization for violating its trademarks, and now we have news of a provider that thinks it is a very good concept to print the visage of an Hermes Birkin on a cheap louis vuitton canvas bag: the V73 Canvas Printed Tote. The day's handbag news is downright retro. you probably could have guessed how this campaign would search louis vuitton speedy sale pale, valuable and ever so sweet. The louis vuitton sale brand tapped Steven Meisel to shoot Daria Strokous and Kati Nescher in the world's most luxurious ice cream shop, and the outcome match the mood in the louis vuitton speedy 25 clothes and accessories perfectly. Check out another shot right after the jump.the Kelly form louis vuitton neverfull MM a straightforward, arm-carried bag having a front flap closure and a major deal withlouis vuitton neverfull is often a traditional form that will not definitely belong to louis vuitton speedy 30 a lot as it belongs to handbag layout in general. Significantly like the louis vuitton luggage, the shape has reached this kind of a classic degree that attributing it to only a single business no longer seems fair. And when the reinterpretations yield bags as unique in the original since thelouis vuitton speedy Postman's Lock Satchel, I believe it is simple to see why I take that opinion 

ChaquetasBelstaff wrote on 3/1/12:

Belstaff Bolsa Los datos más recientes mostraron China foreign exchange Trade Center, el 29 de noviembre, la tasa de paridad central de 6.3587 Yuan frente al dólar, una devaluación Belstaff Chaquetas Hombres del anterior período de sesiones 2 puntos de base, comparado Belstaff chaquetas Mujeres con el 31 de octubre tasa de paridad central de 6.3233 renminbi?os en el futuro el Yuan cayó frente al dólar, mostrar la devaluación del renminbi en las expectativas del mercado hacia adelante.Belstaff Chaquetas icon   "Depreciación MBT Zapatos actual renminbi debido principalmente a China en octubre representaron un crecimiento negativo de refugio deberá iniciar cierto nivel salida de capital a corto plazo. "Banco de comunicaciones, centro de investigación financiera investigador e Belstaff chaquetas Mujeres, pero los márgenes de ganancia en el mercado inmobiliario se más comprimirán, bajo la influencia de la turbulencia en los mercados financierosBelstaff Chaquetasinternacionales, en el mercado de valores de China masivos,. que a su vez afecta la tasa de cambio del Renminbi MBT Outlet

quick weight loss wrote 22 hours, 50 minutes ago:

It truly is a grand story and so the site; I am touched by your story a lot

Leave a Comment

CAPTCHA[Refresh]

« Articles

Article Tags

Show all articles, or just those tagged as:

Feed

The articles RSS feed is available.

Elsewhom

  • Andy Budd::Blogography.
    Web usability chat that's sure to get your pulse racing
  • Ubuntu Blog.
    Not quite everything about Ubuntu, but close
  • The Tech.
    MIT's Student Newspaper
  • If Then Else.
    A weblog by Eduardo Sousa, a film and video geek from Porto, Portugal, with a knack for design and a keen interest in the affairs of mankind
  • Ars Technica.
    The art of technology

See More…

Back to top.