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:


 .  

   
 #!/bin/bash  
   
 NEW_FILE=screenshot__`date +%d-%b-%Y_%T`.png  
   
 case $1 in  
   
  -w)  
    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  
  ;;  
   
 esac  
   
 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

scrnw

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.

Sunday, August 11, 2013

Wallpapers and System Messages on the Desktop

Being that I use a plain window manager on my machine, the desktop root window is just displaying a calm wallpaper for me. In order to facilitate this, I use Nitrogen (cf. website, debian package). It gives me a GTK+ window with thumbnails of my wallpaper directory. I click on the wanted wallpaper, apply and am good to go.




In Openbox, I call Nitrogen via a key combo (I use SUPER + b, as in background) which runs this command:


 nitrogen --no-recurse --sort=alpha ~/Pictures/wallpapers  


--no-recurse tells nitrogen not to go into subdirectories, which is a smart thing to do considering that file managers make smaller thumbnails of the images and you usually have a hidden subdirectory with loads of tiny pictures you actually don't want to be your wallpaper.

--sort=alpha is sorting the images alphabetically. 
Other options: ralpha - reversed alphabetical order, time - according to modified time, rtime - same as time, but reversed.


Of course, Openbox doesn't know that I want to load a wallpaper at startup, so I put this command in my .xinitrc / .xsession (my .xsession is actually just a symlink to my .xinitrc).


 nitrogen --restore &  


An empty root window with a wallpaper gives me the perfect opportunity to have a sort of live display of my system logs. There is this nifty command tool called tail which lets you view the last 10 lines of a text file in the console, while always listening in and updating, so you always get the last log entries.
The same is available for the root window, but as a different programme called root-tail (website, deb).

I have this in my .xinitrc:

 root-tail -g 800x250+40+460 -font -misc-fixed-*-*-*-*-*-100-*-*-*-*-*-1 /var/log/messages  


-g stands for geometry.  This is the standard X stuff - the first 2 numbers are the width and height of the invisible text window in which to present the message. The other 2 numbers are the x and y coordinates on screen. Note that, as root-tail is essentially just console output, the coordinates are lines rather than pixels! You will have to experiment with this one to fit your needs and screen resolution. Mine is 1366x768. Refer to the man page for more.

-font is obvious. I have chosen an old X font without antialiasing (though I'm not even sure if trutype fonts with smoothing are even supported). This is the standard fixed width font and it works well for me.

The last bit is the log file in question. On Debian, I had to allow read access for /var/log/messages. This log shows events like USB keys being plugged in and such and hence is rather useful.





Fin.