Taking screenshot using bash scripts


I am sharing two very simple bash scripts I made that allow to take a screenshot of a portion of the current window. By all means, these are no the best option for taking a screenshot, is just an exercise on how to use bash to do useful things; all needed is install the scrot tool ($ sudo apt install scrot) and use xterm. Is true that I could use instead other command line utilities, like scrotum (screen capture using pygtk, inspired by scrot) or maim (a utility meant to overcome shortcomings of scrot and performs better), but I just wanted to keep it simple :slight_smile: .
The 1st script (ScrotShot) use xterm with parameters to set a small screen, with green letters over black background and execute the 2nd script (TakeShot), that ask for a delay in seconds (0 will abort the script), then ask for select an area of the window using the mouse (0 will abort the script), after that, a countdown will appear with the screen capture happening when it ends. The ouput will be saved in PNG format, where you want it, with a default name that include the date, time and screen capture size in pixels.


 # ScrotShot, V1.0, Author: GFP, January 2018
 xterm -fg green -bg black -bc -geometry 25x2 -fa 'Monospace' -fs 12 -e '<your path for TakeShot>'


 # Takeshot, Version 1.0, Author: GFP, January 2018
 # for further reference, take a look at https://wiki.archlinux.org/index.php/taking_a_screenshot
 echo "Type delay, press ENTER"
 read -r -p 'Seconds: ' secs
 if [ $secs -gt 0 ]
       echo "Select area or 0 to abort"
     scrot -d $secs -c -b -s '<your path for the screenshot>/%Y-%m-%d_%H:%M:%S_$wx$h_scrot.png' 
 # after the delay, scrot will emit a system default beep sound unless using option -z or --silent
 echo "Aborting ..."
 sleep 1

Don’t forget to add the execution permission to the bash scripts, if you want to try them.