the matt jones website.‎ > ‎Scripts‎ > ‎

AutoCam - Automatically Take Screenshots (perl)

Below is a script to automatically take screenshots. It is not beautiful, but it demonstrates how to take screenshots with perl and also how to take screenshots the non-interactive way in gnome/X. the import command as shown can be used to take screenshots from the command line in linux, gnome... etc.

#!/usr/bin/perl -w

# By Matthew Jones, 2010.
# This script takes a screenshot of the current desktop.
# and saves the screenshot to a file in X directory every
# N seconds Y number of times. 

# Script Relies on:
# 1) Perl
# 2) X session running in current environment
# 3) Availability of "import" commnad installed in env.

use Time::localtime;

my $argNum = $#ARGV + 1;

if((($argNum=="1") && ($ARGV[0] eq "H")))
print "Usage:\n";
print " directory times seconds format\n";
print "directory - location images are saved.\n";
print "times - number of images taken.\n";
print "seconds - number of seconds between screenshots\n";
print "format - file format, ie: png, jpg, ps\n";
print "Missing Arguments\n";
print "Usage:\n";
print " directory times seconds format\n";
my $directory = $ARGV[0];
my $times = $ARGV[1];
my $seconds = $ARGV[2];
my $format= $ARGV[3];

my $counter = 0;
my $localEpoch = time();
system("import -window root $directory/$localEpoch.$format");

Matthew Jones,
12 Jun 2010, 04:28