#!/usr/bin/perl # Author: Peter R. Wood, http://prwdot.org/ use strict; #### #### Configuration #### # Path to 'screencapture' utility my $screencapture = "/usr/sbin/screencapture"; # Path to ImageMagick 'convert' utility my $convert = "/usr/local/bin/convert"; # Path to 'who' command my $who = "/usr/bin/who"; # Directory to which the screencapture should be saved my $destination = "/Path/To/Your/Web/Dir"; # Desired filename. Do not include the three-letter extension. my $filename = "screencapture"; # Desired Format. Choose one of 'png' 'jpg' 'pdf' my $file_format = "png"; ######### MAIN PROGRAM ## Check to see if someone is logged in to the console. If not, skip it. my $wholist = `$who`; chomp($wholist); if ( $wholist =~ /console/go ) { # Run screencapture my $screencap_command = "$screencapture $destination/$filename.pdf"; system($screencap_command) || die "Couldn't run $screencap_command: $!\n"; print "Capture was successful.\n"; # Do we need to convert the file? if ( $file_format ne 'pdf' ) { my $convert_command = "$convert $destination/$filename.pdf $file_format:$destination/$filename.$file_format"; system($convert_command) || die "Couldn't run $convert_command: $!\n"; print "Convert was successful.\n"; } } else { die "Nobody logged in - nothing to capture.\n"; }