Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-27-2002, 10:42 PM   #1
Registered: Jun 2002
Location: USA
Distribution: Slackware8.1
Posts: 332

Rep: Reputation: 30
Need a simple script that will take screenshots and ...

Hi. Is there a simple C program or bash script(not so sure that a script would work though) that I could write or anyone could show me that would take a snapshot of a certain window on the screen and then save it to a numbered file such as cap1.jpg cap2.jpg etc. and be able to map a key on the keyboard that would take the snapshot?

New to C and learning
Old 06-28-2002, 08:22 AM   #2
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
there are a number of C headers & libs I've seen floating around that will simplify writing to jpg (or jpeg) format. As for the screenshots, uh......why dont you try to uh.....hmmm.......find the printscreen ascii's value; trigger the printscreen button; take from whereever the button puts the screen in memory and write it out to a file (ordered by # like you said)? I don't know if this is feasable, but if you look into it, I'm sure you'll find plenty of useless information that is actually quite intresting . I'd be suprised to find a script that wrote jpeg (or jpg) format (except Perl, that wouldn't suprise me).
Old 07-07-2002, 04:38 PM   #3
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
use gimp. Gimp comes with the screenshot plugin.

You can use scriptFU or PerlFU to extend it's functionality if needed beyond that.
Old 07-08-2002, 08:32 PM   #4
LQ Newbie
Registered: Jul 2002
Posts: 1

Rep: Reputation: 0

Hey, just what I was working on (and needing amateur bash help on). On the command line you can do the following command to get a jpeg screenshot of the whole screen:

import -window root screenshot.jpeg

If you want a screenshot of just one window type:

import screenshot.jpeg

and you select the window with your mouse.

Here's a simple 2-line BASH shell script to do it:

#! /bin/sh
import screenshot.jpeg

Wow, what a guru I am, huh? That script puts out a jpeg in your current directory. You can change it a little to suit you such as replacing 'screenshot.jpeg' with /home/yourname/cap.jpeg and you get a jpeg in your home directory.

And now my question: Every time I run that script, it saves it as 'screenshot.jpeg', so if there is already one, it overwrites it. What can I add to name them in ascending order, like cap1.jpg cap2.jpg etc
Old 07-08-2002, 09:08 PM   #5
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 30
I haven't tested this but something like that should work

while [ -f "$NAME$COUNT.jpg" ]
COUNT=`expr $COUNT + 1`
import $NAME$COUNT.jpg

'man test' for how to use the '[' ']' operator and what the '-f' means. '-f' tests to see if the file by that name exists.

'expr' increments the COUNT variable.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
New to C++ help with simple script Fredstar Programming 9 08-08-2005 11:09 AM
A Simple Script fiod Linux - General 3 09-20-2003 08:56 PM
Simple Script fiod Linux - General 2 09-08-2003 03:03 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration