Sometimes I've wanted to take screen shots, especially of full screens and sometimes rapidly. Utilities like KDE "Snapshot" or Gnome "gnome-screenshot" simply don't cut it as they, being GUI oriented, require them to overlay the screen which isn't possible in full screen mode, So to use them a delay needs to be specified, then switch to the full screen and hope you got the scrape you were looking for.
The command line comes to the rescue again! 'ImageMagick' comes on most Linux distros and the solves the problem with a tool .... "import". A command line as simple as:
import -window root pic.jpg
will capture the root window and store it as a file named "pic.jpg". However, the same problem exists. You need to set a delay as you need to restore the main screen before the snapshot is to be taken.
The solution to this problem is to bind a key to the "import" command. The tool for this is "xbindkeys". To use xbindkeys you need to do three things:
From a terminal window type:
xbindkeys -k
A small screen appears. Mouse click in the window to make sure it is the active window and press the key of your choice, in this example press the "print screen" key. The small window disappears and in the terminal window you will see:
You can use one of the two lines after "NoCommand" in $HOME/.xbindkeysrc to bind a key. "(Scheme function)" m:0x0 + c:107 PrintThese are two different ways to represent the "Print Screen" key. I prefer to use the non-scheme method and use "Print". We now know the two major things required for the file ".xbindkeysrc": a key to be bound "Print" and the command it's to be bound to "import -window root pic.jpg".
The .xbindkeysrc file has the form:
"command" keySo create an ASCII (text) file named ".xbindkeysrc" with your favorite editor (I hope it's "vi") and insert on the first line:
"import -window root pic.jpg"
in quotes as I've shown and on the second line insert:
To activate the key binding all that's required is to type:
xkeybindings
in the terminal window and press <Enter>. Now whenever you press the "Print Screen" key you will capture the current root window in a file named "pic.jpg".
This was still troublesome to me as I sometimes want to take several scrapes in a short period of time and, of course, as there's a fixed filename "pic.jpg", only the last scrape is saved. The solution is to place the "import" command in a script file along with an auto incremented counter. Edit a file ".cap":
num=`cat ~/.num` /usr/bin/import -window root pic$num.jpg num=`expr $num + 1` echo "$num" > ~/.numPurists using bash shell only, could write the above as:
read < .num /usr/bin/import -window root pic$REPLY.jpg echo $((REPLY+=1)) > .num
which is arguably "faster" as it spawns fewer processes but is moot as the "import" command controls the rate at which captures can be made. The leading "." in the name hides the file so I don't accidently erase it. Create another hidden file ".num" with the single digit "0" in it. Change the first line in .xbindkeysrc from:
"import -window root pic.jpg"
to: "./.cap"
Make sure .cap is executable:
chmod 744 .cap
and you're good to go. Pressing the "Print Screen" key several times now creates files with successive names "pic0.jpg", pic1.jpg", ....
One cautionary note: If you're going to do rapid captures immediately, take a throwaway shot first so scripts and applications are hashed and ready to use on subsequent captures.
Here's a family portrait I just scraped using the instructions above:
and another I had taken just before: