Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Tasfiahm
Creator
Creator

Can I use a talend job to take a screen shot after a process is complete and store in a folder

Hi Gurus,

 

I have the challenge to create a talend job that is going to take a screenshot of a particular part of a window and store it in a folder. I know its not a traditional requirement but I want to check the current possibility with talend.

 

Thanks

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

This is a bit of a hack as controlling other applications in Java is a bit hit and miss. What you can do is open the folder you wish to screenshot, pause the code for a few seconds and then take a screenshot of the whole screen. I have tried this and it seems to meet your requirements. The code I used is below....

 

java.awt.Desktop.getDesktop().open(new java.io.File("/Users/richardhall/Desktop"));

Thread.sleep(5000);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Rectangle captureRect = new java.awt.Rectangle(0, 0, screenSize.width, screenSize.height);
java.awt.image.BufferedImage capture = new java.awt.Robot().createScreenCapture(captureRect);
javax.imageio.ImageIO.write(capture, "bmp", new java.io.File("/Users/richardhall/Desktop/screen.bmp"));

View solution in original post

10 Replies
Anonymous
Not applicable

This code will capture the top left quarter of the screen. You will have to play around with the dimension settings to capture what you want....

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Rectangle captureRect = new java.awt.Rectangle(0, 0, screenSize.width / 2, screenSize.height / 2);
java.awt.image.BufferedImage capture = new java.awt.Robot().createScreenCapture(captureRect);
javax.imageio.ImageIO.write(capture, "bmp", new java.io.File("/Users/richardhall/Desktop/screen.bmp"));

I've set my path to my desktop, you'll need to change that as well.

TRF
Champion II
Champion II

@rhall, allways there when needed.
Nice shot!
Anonymous
Not applicable

Thanks @TRF. This one was a weird one, but caught my interest 🙂

Tasfiahm
Creator
Creator
Author

Thanks for the initial solution. I know it is weird. Now comes the weirdest part. Instead of the screenshot of the current window I want to take a screenshot of a particular folder where I have created the file. So far I am able to generate a text file where it is able to list all the files that are inside the folder but I want to take a screenshot of that folder.

 

I know it a lot of hard work but I will appreciate your contribution. 

 

 

Anonymous
Not applicable

This is a bit of a hack as controlling other applications in Java is a bit hit and miss. What you can do is open the folder you wish to screenshot, pause the code for a few seconds and then take a screenshot of the whole screen. I have tried this and it seems to meet your requirements. The code I used is below....

 

java.awt.Desktop.getDesktop().open(new java.io.File("/Users/richardhall/Desktop"));

Thread.sleep(5000);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Rectangle captureRect = new java.awt.Rectangle(0, 0, screenSize.width, screenSize.height);
java.awt.image.BufferedImage capture = new java.awt.Robot().createScreenCapture(captureRect);
javax.imageio.ImageIO.write(capture, "bmp", new java.io.File("/Users/richardhall/Desktop/screen.bmp"));
Tasfiahm
Creator
Creator
Author

You are exactly near(99%) of the requirement. With your code, the window is opening and taking a screenshot but it is not closing the window.  I tried to add addition code to close the window but I got this error :

Detail Message: The method close(File) is undefined for the type Desktop
There may be some other errors caused by JVM compatibility. Make sure your JVM setup is similar to the studio.

 

CODE

java.awt.Desktop.getDesktop().open(new java.io.File("/Users/TA/Pictures/My_Pic"));

Thread.sleep(5000);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Rectangle captureRect = new java.awt.Rectangle(0, 0, screenSize.width / 1, screenSize.height / 1);
java.awt.image.BufferedImage capture = new java.awt.Robot().createScreenCapture(captureRect);
javax.imageio.ImageIO.write(capture, "bmp", new java.io.File("C:/Temp/screen2.bmp"));

Thread.sleep(5000);
java.awt.Desktop.getDesktop().close(new java.io.File("/Users/TA/Pictures/My_Pic"));

 

so how I can close the window. It's really exciting what we can do with TALEND.

Anonymous
Not applicable

The method we have used so far is not going to allow you to close the window, I'm afraid. You *could* kill the process, but unless you really know what you are doing, that could be dangerous. To find the process using Java, you can use the code below (found here: https://stackoverflow.com/questions/54686/how-to-get-a-list-of-current-open-windows-process-with-jav...).

 

try {
    String line;
    Process p = Runtime.getRuntime().exec
    (System.getenv("windir") +"\\system32\\"+"tasklist.exe");
    BufferedReader input =
            new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
        System.out.println(line); // Add code to identify your process id here
    }
    input.close();
} catch (Exception err) {
    err.printStackTrace();
}

Once you have identified the process used by the window you want to close, you can just kill the process. 

 

I haven't written code to do this for you as it involves too many unknowns for me. I am on a Mac and you are on Windows. You should be able to figure something out from the data you will get here.

Tasfiahm
Creator
Creator
Author

Thanks a lot for your effort. I understand how critical the close function is!!! I don't want to kill/close any app accediently!! But you have allowed me to do a head start. I really appreciate your help.

Anonymous
Not applicable

No problem, it was an interesting question 🙂