LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need a simple script that will take screenshots and ... (https://www.linuxquestions.org/questions/programming-9/need-a-simple-script-that-will-take-screenshots-and-24488/)

purpleburple 06-27-2002 10:42 PM

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?

thanks :)
New to C and learning

lackluster 06-28-2002 08:22 AM

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).

kervin 07-07-2002 04:38 PM

use gimp. http://gimp.org/ Gimp comes with the screenshot plugin.

You can use scriptFU or PerlFU to extend it's functionality if needed beyond that.

Crow 07-08-2002 08:32 PM

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

kervin 07-08-2002 09:08 PM

I haven't tested this but something like that should work

#!/bin/sh
NAME=screenshot
COUNT=1
while [ -f "$NAME$COUNT.jpg" ]
do
COUNT=`expr $COUNT + 1`
done
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.


All times are GMT -5. The time now is 12:28 AM.