Header Shadow Image


Screenshot: How to get a screenshot in linux using command line tools: xwininfo, convert.

Sometime back I was wondering how I can get a screenshot in Linux.  I've created this workaround for myself to use from the shell not knowing about the GIMP screenshot capture/aquire function at the time:

$ xwininfo|grep "Window id:"|awk '{ print $4 }'| awk '{ print "xwd -id "$1" -out screenshot.pcx" }'|sh;convert -colors 256 -dither screenshot.pcx screenshot.jpg;if [ -f `pwd`"/screenshot.jpg" ]; then echo "File saved to 'screenshot.jpg'"; fi
File saved to 'screenshot.jpg'

$

The great thing about this is that it gave me the option to possibly capture screenshots from a script, which could have a number of important uses.

HOW DOES IT WORK?

The above is a one line command.  Paste it to a command prompt as you see it.  It uses 'convert' and 'xwininfo' utilities one being an image converter the other the X Windows Information utility respectively to determine which windows your cursor us over.  The third part is 'xwd' which is an X Windows image Dump utility.  When command is ran, your cursor should change to a '+' sign indicating that 'xwininfo' is ready to determine the windows you currently are over.  Click your mouse button over the window you need and next thing you'll have a screenshot of the window in the current folder.   'man' pages has more information on each of the commands so give them a try.  Also use '–help' with each one to tweak to your taste.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License