When I’m using Windows or OS X, I use a utility called Tinygrab to quickly share screenshots over the internet, whether it’s via Twitter, IM, email, etc. The concept is simple: you press a key combination, select a region of your screen, and it uploads a screenshot of that area and gives you a URL for sharing. Unfortunately, they don’t (currently) support Linux, and so I decided to create my own version.
Since this was the result of an hour or two of bash scripting, it’s somewhat limited in what it can do. I’m planning on expanding it in the near future to support GUI configuration and not rely on Compiz in order to take the screenshot. Since Compiz causes some wackyness when it comes to grabbing screens, I’m using Compiz’s Screenshot plugin, which you can enable in CompizConfigSettingsManager. By default, the shortcut is to hold Super (aka, the Windows key) and drag your mouse button to select an area to grab. You’ll need to set two options in order for my script to work. First, the directory to save the images to. I used ~/Desktop, since the script deletes the image after it has been uploaded, however you could also use something like /tmp if you like. Second, the command to be run on the screenshot after it has been saved, which is the script you see below. I saved it to ~/bin/upload_image, but again, you can call it whatever you like, just be sure to make the file executable.
The next step is to install the necessary dependencies. Since I’m reply on a few applications, you’ll have to have the following packages installed (this is on Ubuntu 10.04), but again, I’m hoping to change this in the near future: libnotify-bin and xclip.
The script also assumes you have passwordless ssh set up with your server (yes, you do need your own server for the moment, I’m hoping I can change this in future versions) You can easily do this in Ubuntu via the “Password and Encryption Keys” item under Accessories.
Now that all that is in place, it’s time for the script. You’ll notice there are a few values you need to fill in:
#!/bin/bash
user=
server=
destdir=
httpstr=
if [ ! -e $1 ]; then
notify-send “Error” “File does not exist” -i error
exit
fi
md5=`md5sum $1`
if [ "$?" -ne 0 ]; then
notify-send “Error” “Could not generate md5sum” -i error
exit
fi
md5=${md5/ */}
scp $1 “$user@$server:$destdir${md5}.png”
if [ "$?" -ne 0 ]; then
notify-send “Error” “Failed upload” -i error
exit
fi
longurl=$httpstr$md5.png
shorturl=`wget http://is.gd/api.php?longurl=$longurl -O-`
if [ "$?" -ne 0 ]; then
notify-send “Error” “Failed to shorten URL” -i error
$shorturl=$longurl
fi
echo $shorturl | xclip -selection clipboard
notify-send “Upload Complete” $shorturl
rm $1
Those values that you need to fill in are:
user: your username on the server
server: the address of the server you’re uploading your images to
destdir: a directory on that server that’s accessible via the web, such as /var/www/screengrabs/
httpstr: the url to that directory, for example: http://www.mysite.com/screengrabs/
Once all that’s set up, try it out. Hold Super and drag your mouse to select an image on your screen. Wait a few seconds and you should either get an “Update Complete” notification, or an error with what went wrong. If the upload was a success, you’ll have a url on your clipboard shortened with is.gd, ready for the pasting.
Enjoy
Update: Bonus: Here’s how you can make use of my script without needing Compiz. I haven’t tested it yet, but it should work. You’ll need Imagemagick installed.
#!/bin/bash
import /tmp/screenshot.png
/path/to/other/script /tmp/screenshot.png
Save that and bind it to a hotkey and you should be good to go.