Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

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

Highlighted
Six Stars

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


Accepted Solutions
Highlighted
Community Manager

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

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


All Replies
Highlighted
Community Manager

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

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.

Highlighted
Sixteen Stars
Sixteen Stars

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

@rhall_2_0, allways there when needed.
Nice shot!

TRF
Highlighted
Community Manager

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

Thanks @TRF. This one was a weird one, but caught my interest :-)

Highlighted
Six Stars

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

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. 

 

 

Highlighted
Community Manager

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

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

Highlighted
Six Stars

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

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.

Highlighted
Community Manager

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

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.

Highlighted
Six Stars

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

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.

Highlighted
Community Manager

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

No problem, it was an interesting question :-)

 

Highlighted
Six Stars

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

Java experience with Talend is a killer combo in ETL!!! keep it up....

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog