Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A Perl script to automate screen captures UNIX
Here's a little perl script I came up with:
  #!/usr/bin/perl

number = "00000";

while(1)
{
$newfile = $number.".jpg";
sleep 10;
`screencapture -m -x ~/Documents/$newfile`;
$number++;
}
What does it do? Simple - it takes a screenshot every 10 seconds and saves it as a .jpg file. I've double checked this in Graphics Converter - it is a .jpg file. I do have Quicktime 6 Pro, so your mileage may vary.

From here, you can tweak this program to your liking. For guys like me who do DVD/game reviews, this is handy so we don't have to reach for the Command-Shift-3 key all day long (especially when that's disabled during a DVD movie).

[Editor's note: Standard shell script stuff - Save the file, make it executable with chmod 755 script_name and make sure it's saved somewhere in your path...]
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[14,602 views]  

A Perl script to automate screen captures | 15 comments | Create New Account
Click here to return to the 'A Perl script to automate screen captures' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
error
Authored by: salty on Sep 04, '02 10:53:57AM

[XXX.XXX.XXX.XXX:~] nick% ~/screencapture
Can't modify constant item in scalar assignment at /Users/nick/screencapture line 3, near ""00000";"
Execution of /Users/nick/screencapture aborted due to compilation errors.



[ Reply to This | # ]
error
Authored by: lamon on Sep 04, '02 11:21:19AM

Add a $ character before 'number' on line 2.

Lga.



[ Reply to This | # ]
Proper Notes
Authored by: Dark Paladin on Sep 04, '02 11:49:49AM

Let me make some corrections:

number = "00000"; should be:

$number = "00000";

The proper way to do this would be:

From terminal, type "pico screenshoter.pl" (or whatever you want to name the program).

Put in the code as mentioned (making your you correct my $number boo-boo ;) ).

Save with Control-X, yes to save.

Type "chmod 755 screenshoter.pl" - what this means is make it Readable, Writable, and Executable by me, and Readable and Executable by everyone else. (If you're a paranoid type, just make it 700 to only *you* can play with it).

To run, type ./screenshoter.pl, or (assuming you saved it in your home directory), ~/screenshoter.pl.

I made this a Perl script (just because I like Perl), and again, I've got Quicktime Pro 6. If anyone does *not* have Quicktime Pro 6, and this works for them, let me kow.



[ Reply to This | # ]
Be careful there!!!!
Authored by: Glanz on Sep 04, '02 12:49:15PM

Make an auto delete that is time based also! If not, that could be made into a virus. Even then!!!! Be careful....



[ Reply to This | # ]
2 changes
Authored by: matx on Sep 04, '02 03:19:45PM

two changes....
change externsion to PDF for 10.2 and destination: pictures folder

-matx

<snip>

$number = "00000";

while(1)
{
$newfile = $number.".pdf";
sleep 10;
`screencapture -m -x ~/Pictures/$newfile`;
$number++;
}
<snip>









[ Reply to This | # ]
jpeg2000 works too
Authored by: iobuffa on Sep 04, '02 07:02:26PM

Try using the .jp2 extension..it works in 10.2 for me.. :-)



[ Reply to This | # ]
Has anyone considered
Authored by: victory on Sep 04, '02 08:02:11PM

the spyware capabilities that this new 10.2 command gives to *any* user account on an OSX box? Just a cautious reminder to all who might have enabled remote (shell) logins on their systems.



[ Reply to This | # ]
Has anyone considered
Authored by: chmod007 on Sep 04, '02 08:46:31PM

Not so. screencapture will only capture the screen if the user who executes the command is also logged in locally at the computer, or is root. This is because the screencapture requires a connection to the windowserver.



[ Reply to This | # ]
Has anyone considered
Authored by: Anonymous on Sep 05, '02 11:25:01AM

Not a security hole -- try it.

If you run screencapture as a different user, it can't connect to the window server and, hence, can't take a screenshot.



[ Reply to This | # ]
Duh. (Has anyone considered)
Authored by: victory on Sep 08, '02 04:40:36AM

You two are, of course, entirely correct. I should have tested this myself before posting a comment that might worry others.



[ Reply to This | # ]
not jpegs here
Authored by: paygun on Sep 04, '02 10:31:56PM

this works for me, but the file is not a jpeg. I can make screencapture save a file named *.jpg, *.doc, or even *.mov but the file type is the same. I also have QT6 pro. There\'s a unix utility included with OS X called \"file\" that actually looks into the contents of a file to determine it\'s type. OS X and Solaris\' version of file both tell me that the grabs made this way are pdf files.
The grabs I made called whatever.mov also work fine, but they ain\'t movies. :)

Maybe my setup here is different, I don\'t know.



[ Reply to This | # ]
another test
Authored by: paygun on Sep 04, '02 10:42:22PM

I also transferred the file to a pc, my graphic viewer (Irfanview) can't read the file, as it doesn't read pdfs. Acrobat reader loads the file fine.

Was there something else that needs to be done to make screencapture write jpeg files?

thanx



[ Reply to This | # ]
another test
Authored by: vashremix on Sep 04, '02 11:16:05PM

once it was writing .jpg files... if it could upload them to an ftp server you'd have a very unique kind of "web cam" sort of a "desktop cam"!

That would be cool.


Vash



[ Reply to This | # ]
screen capture script oddities
Authored by: webmastermac on Sep 04, '02 11:55:05PM
for some reason only jp2 and pdf format work for me. I even made an applescript to play w/this feature, but only these 2 formats work. Any ideas?

[ Reply to This | # ]
screen capture script oddities
Authored by: faxeTV on Sep 07, '02 09:45:12AM

hi,

tried it with .jpg & .jpg2, still Acrobat Reader can open it (and Preview not btw) seems to be a PDF document whatever i am doing



[ Reply to This | # ]