Sunday 28 July 2013

Linux Screen Capture Script

This bash script uses scrot as back-end so you will need scrot installed on your system. scrot is available in repository of almost every distribution.
Why not use scrot directly you might ask?

You can use scrot on it's own but you will need to remember and type all the options in order to harness the power of scrot. This simple script makes it easy for everyone to capture entire screen, Window in focus or any part of desktop or window according to need without remembering scrot options.

What's more it saves all the captured images in '~/Pictures/Screenshots' directory. It will create this directory if it doesn't exist. It will name the screenshot according to the time it was captured on. This time stamping makes it easy to sort screenshots later-on.






So without further delay here's the script. Save it somewhere in path and make it executable. Using it is pretty self-explanatory.


#!/bin/bash
DIR="${HOME}/Pictures/Screenshots"
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"

clear

if [ ! -d "${DIR}" ]; then mkdir "${DIR}"; fi

echo -e '\E[1;36m'"***** HAKERDEFO'S SCREEN SHOOTER *****";

echo -e '\E[1;32m'"*****^^^^^^^^^^^*^^^*^^^^*^^^^^^^*****";

echo -e '\E[1;36m'"Select one of the following options: ";

echo -e '\E[1;32m'"*****^^^^^^^^^^^*^^^*^^^^*^^^^^^^*****";

echo -e '\E[1;32m'"Press"'\E[1;36m' "[E]" '\E[1;32m'"To Take The Screenshot Of The Entire Screen.";

echo -e '\E[1;32m'"Press"'\E[1;36m' "[W]" '\E[1;32m'"To Take The Screenshot Of Window In Focus.";

echo -e '\E[1;32m'"Press"'\E[1;36m' "[A]" '\E[1;32m'"To Take The Screenshot Of Area Selected By Mouse.";

read option

case "$option" in

"E" | "e" )
clear
echo -e '\E[1;33m'"Minimize Terminal To Avoid It From Being Captured...";
scrot -d15 -c "${NAME}"
clear
echo -e '\E[1;36m'"$SHORT_NAME Saved in '$DIR'.";
;;

"W" | "w" )
clear
echo -e '\E[1;33m'"Minimize Terminal And Bring The Window To Be Captured In Focus...";
scrot -u -d15 -c "${NAME}"
clear
echo -e '\E[1;36m'"$SHORT_NAME Saved in '$DIR'.";
;;

"A" | "a" )
clear
echo -e '\E[1;33m'"Draw A Rectangle On The Screen And Area Inside It Will Be Captured...";
scrot -s "${NAME}"
clear
echo -e '\E[1;36m'"$SHORT_NAME Saved in '$DIR'.";
;;

* )
clear
echo -e '\E[1;36m'"Incorrect Option Selected. Bye... Bye...";
sleep 1
echo -e "\033[0m"
clear
;;

esac

echo -en '\e[0m';

exit 0


Suggestions, ideas are welcome!!!
Cheers!!!

No comments:

Post a Comment