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:
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:
#!/bin/bash # Declare FTP access details FTPSERVER=ftp.example.com USERNAME=screenshots@example.com PASSWORD=password # Declare the local directory to which the file should be saved. dir=~/screenshots # Declare a filename. I used a timestamp as a simple way to get a unique filename. filename=myscreenshot-$(date +%Y-%m-%d_%H%M%S) # Declare the URL of the directory to which the file will be uploaded. url=http://example.com/screenshots/ # After a delay of 2 seconds, save a PNG screenshot. scrot -d 2 -q 1 "$dir/$filename.png" # Upload the screenshot. ncftpput -u $USERNAME -p $PASSWORD $FTPSERVER / $dir/$filename.png # Copy the URL of the uploaded screenshot to the clipboard. echo "$url$filename.png" | xclip -selection c 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.
# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" 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.

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.
Leave a Comment
Article Tags
Show all articles, or just those tagged as:
- Apache (1)
- CakePHP (10)
- Domains (1)
- Freeware (1)
- Graphics (1)
- Life (1)
- Open Source (2)
- Servage (1)
- SMS (1)
- Software (3)
- Ubuntu (2)
- WAMP (2)
- Web Development (13)
- Windows (2)
- Work (2)
Feed
The articles RSS feed is available.
Elsewhom
-
Ubuntu Blog.
Not quite everything about Ubuntu, but close -
Coding My Thoughts.
Java, PHP, and some other technological mumble jumble. Also, some real-life stuff as well. -
Never Knowingly Underwhelmed.
Andrew Collins is a journalist, scriptwriter and broadcaster -
hackdiary.
Matt Biddulph's blog - Edinburgh's Dark Side.
