Using ImageMagick's import to capture screenshot of a desktop or specific window and store it as a PNG image file.
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Usage: `"$BASENAME_BIN" $0` desktop|window" 1>&2
exit 1
fi
if [ x"$1" = xdesktop ]
then
import -window root ~/screenshots/desktop-$(date +'%Y%m%d%H%M%S').png
elif [ x"$1" = xwindow ]
then
import -frame -window $(xprop _NET_ACTIVE_WINDOW -root | awk '{print $5}') ~/screenshots/window-$(date +'%Y%m%d%H%M%S').png
fi