DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Capture Window To File

04.29.2009
| 3509 views |
  • submit to reddit
        Extremely simple script to capture a window to a file.

#!/bin/sh
#
# Capture window image and save file
#
# Dependencies: imagemagick
#
set -e

# Main

test $# -ge 1 || { echo "Usage: capture_window FILE [SECONDS]"; exit 1; }
FILE=$1
WAIT=$2
test "$WAIT" && sleep $WAIT  
import - | convert - $FILE
echo $FILE