Wednesday, August 14, 2013

Screenshots in Window Managers with Zenity, Scrot and Gpicview

TECHNICAL UPDATE: Code snippets will be dark green from now on. I am still working on making proper code boxes with select all function and all the jazz.

There are a lot of dedicated screenshooters out there, some more advanced than others. I need something simple and want to facilitate it with the tools I already have on my machine or that need just a few more lean programmes.

scrot (HQ, deb)
zenity (HQ, deb)
gpicview (HQ, deb)

scrot is just a small screenshot wrapper around imlib2 and quite lean.

Why gpicview? It's my go to image viewer and it can save files. So, if you substitute this with something else, choose one that lets you easily save the picture, since the script will only save into /tmp and then delete the file immediately!

Basically, there are 2 ways of using this script. It will wait for a certain interval (I've set it to 3s) after which it will either make a screenshot of the whole screen, or, in the second mode where you call the script with the -w flag, you either click on a window you want, or draw a rubber band around the screen portion you want.
In both cases, a zenity window will pop up to warn or instruct you.
After that, gpicview will display the image. That's where you can actually save the picture by using the right click dialogue, as the temporary picture in /tmp will be deleted once you close gpicview!

The script proper:


 NEW_FILE=screenshot__`date +%d-%b-%Y_%T`.png  
 case $1 in  
    zenity --title "Selective screenshot" --info --text "Please select a portion of the screen by holding down the left mouse button and drawing a rectangle, or just click on the window you would like a screenshot of." && scrot -s -d 3 /tmp/$NEW_FILE && gpicview /tmp/$NEW_FILE && rm /tmp/$NEW_FILE  
    zenity --timeout 2 --title "Fullscreen screenshot" --info --text "Making a screenshot of your entire screen..."  
    scrot -d 3 /tmp/$NEW_FILE && gpicview /tmp/$NEW_FILE && rm /tmp/$NEW_FILE  
 exit 0  

WARNING: Both bold parts in the script are 1 line and are only broken up here because of the blog!

I save the script as scrnw and call the command


with the Print Screen button in case I need a full screen shot, or as

scrnw -w

with Alt-Print Screen in case I need just a portion of the screen or a window.
Here's a screenshot of the dialogue in this case:

That's it.

No comments:

Post a Comment