uwshot: The Unix-way of making screenshots

Initially published on 2008-08-26.

This is a script to quickly save an image of a screen region.

It's built in the "Unix-way", that is, by linking together several small and simple programs to achieve a greater result.

It is quite short and trivial in itself, but due to that can also be useful as a demonstration of what shell-scripting is capable of. Also, it is useful for its direct purpose at least to me, because I could find no other program which would combine all the features implemented in this script, and do so requiring similarly low number of clicks/actions.

Notable dependencies

  • scrot - to make screenshots
  • pngcrush (optional) - to make screenshots smaller
  • zenity - to show dialog boxes



1. Shooting

When you launch this script, you can:

  • either select a screen region to be captured, by pressing the left mouse button, then dragging the mouse;
  • or select a window to be captured in its entirety, by clicking somewhere inside it.

After that, you will be informed about the screenshot size and asked to give it a descriptive name, not necessarily a unique one (because a timestamp will also be appended to the name), just for somehow identifying it later among other screenshots:

At this point you may decide to not enter anything and press “Cancel” instead - then, the screenshot will be deleted. Or, if you enter the name and press OK, it will be saved into the current directory.

2. Sharing

This script was written by me specifically as a way to quickly create screenshots to share them through my local web server, i.e. to make the process of creating a screenshot, naming it and getting its complete URL into the clipboard (for pasting into IRC or IM conversations) as hassle-free as possible. For that reason, it can take one argument, which specifies the base URL, by which the current directory is accessible from the web.

So, after you have given the screenshot a short name, you will be presented with the same entry window again, but this time it will contain full URL to your screenshot (as accessible from the Web), for the purposes of copying it to the clipboard (and then pasting wherever you like):

Modifying the URL in that window will have no effect; the text entry dialog is used here just to simplify copy-pasting. However, if you decide that you would rather not have that screenshot, you can press “Cancel” and it will be deleted.

Examples of invocation

Let's suppose the following:

  • You have installed or symlinked this script into a directory which is in your PATH (e.g. into /usr/bin/, or /usr/local/bin/);
  • the web server on your computer serves pages from /var/www/;
  • that web-server is accessible from the Internet as http://www.example.com/.

Then, you can use this script as follows:

cd /var/www/
uwshot.sh http://www.example.com/

If you would like to create a shortcut for that in your desktop environment's menu or in a quick-launch panel, you may need to specify the command to be run as follows:

/bin/sh -c "cd /var/www/ && uwshot.sh http://www.example.com/"

uwshot.txt · Last modified: 2015-09-16 09:07 UTC by rm