#!/bin/sh

# grab.sh
# -------
# A quick and simple script to take full or partial screenshots.
#
# Required: import (part of the ImageMagick library)
# 
# Original code by: Micxz (e-mail: grab [at] micxz.com)
# Modified by: d1s4st3r (e-mail: d1s4st3r [at] gmail [dot] com)


# you may want/need to modify these variables...
PROGNAME="import"
PROGPATH="/usr/bin/$PROGNAME"
FILEDESTDIR="/tmp"
FILEHEAD="Screenshot"


MYPROG=`which $PROGNAME | tr -d ''`


if [ "$MYPROG" != "$PROGPATH" ] ; then
  echo "Sorry, unable to find $PROGPATH."
  echo ""
  exit 0
fi


case "$1" in

-f)
   RANDTIME=`/bin/date +%Y%m%N | tr -d ' '`
   TMPFILENAME=$FILEDESTDIR/$FILEHEAD\_$RANDTIME.jpg;
   $MYPROG -window root "$TMPFILENAME"
   echo "Full grab done. File \"$TMPFILENAME\" saved."
   echo ""
   ;;

-m)
   RANDTIME=`/bin/date +%Y%m%N | tr -d ' '`
   TMPFILENAME=$FILEDESTDIR/$FILEHEAD\_$RANDTIME.jpg;
   $MYPROG "$TMPFILENAME"
   echo "Manual grab done. File \"$TMPFILENAME\" saved."
   echo ""
   ;;

-h)
   echo "  Usage:  grab.sh [command]"
   echo ""
   echo "  Commands:"
   echo "    -f       Grab the entire X server screen."
   echo "    -m       Manually grab the screen with your mouse."
   echo "    -h       Display this list of options."
   echo ""
   exit 1 ;;

esac
exit 0

