Is it possible to get a screenshot of the entire desktop directly in Mathematica?

I am on Ubuntu running Mathematica 8. For some reason GUIScreenShot[] fails. But something like GUIScreenShot[{{0, 500}, {0, 500}}] works

It is strange that in the reference


is given as an example (last one), with the caption Capture the entire screen:. But when I copy it and paste it in a notebook, it expects a parameter! (I have included the code Needs["GUIKit`"])

I get the error as shown in this image

Screenshot of the image

  • 2
    $\begingroup$ I am trying to automate a simple game (!). So grabbing it using an external program, then saving it as a file and importing the file again from within Mathematica is a tedious job (if not realtime). Also I am not sure if I can pipe the output of a program as input to Mathematica (I could not find a way to get it done with Run[] command! - i.e. the piping large output from external program) $\endgroup$ – my account_ram Aug 11 '12 at 23:16
  • $\begingroup$ GUIScreenShot[] works here (Win XP) $\endgroup$ – Dr. belisarius Aug 11 '12 at 23:34
  • $\begingroup$ GUIScreenShot[] doesn't work for me (Arch Linux), it spits this error message on the terminal. Looks like a Linux issue... $\endgroup$ – Renan Aug 12 '12 at 0:14
  • $\begingroup$ It works fine on my win7_x64 and mma8.0.4 (although a syntax indicator). Didn't know this function before. Very helpful! Thanks and +1! $\endgroup$ – Silvia Aug 12 '12 at 6:52
  • $\begingroup$ GUIScreenShot[] works in version 7 under Windows 7. $\endgroup$ – Mr.Wizard Aug 12 '12 at 7:55

GUIScreenShot[] (without arguments) works perfectly fine on my Mac, although the front end syntax highlighter indicates a missing argument. As a workaround, you can explicitly give it the dimensions of your screen so that all of it is captured. Here's how you can programmatically get your screen size and use it:

GUIScreenShot["FullScreenArea" /. Flatten@SystemInformation["Devices", "ScreenInformation"]]
  • 1
    $\begingroup$ This does not seem to work on Ubuntu .. Can any1 confirm this ... $\endgroup$ – my account_ram Aug 12 '12 at 0:58
  • $\begingroup$ @myaccount_ram I'm having the same problem, but with Arch Linux. $\endgroup$ – Renan Aug 12 '12 at 4:00
  • $\begingroup$ @myaccount_ram It doesn't work on Fedora. $\endgroup$ – b.gates.you.know.what Aug 12 '12 at 7:34
  • $\begingroup$ I got ** Raster data contains 0 values per pixel; 3 or 4 are required with ColorFunction->RGBColor** under Linux 64. $\endgroup$ – Fred Kline Aug 12 '12 at 20:39
  • 1
    $\begingroup$ @everyone: The issue seems to be something related to linux and not Mathematica. I would've helped if I could, but I don't have a license to use on my Linux machine. $\endgroup$ – rm -rf Aug 13 '12 at 1:53

A method from Kuba's answer, no GUIKit` is needed. Tested on Mathematica 10.1.

Module[{masknb, img},
       masknb = CreateWindow[{}, WindowSize -> Full, Visible -> False];
       img = MathLink`CallFrontEnd[FrontEnd`NotebookImage[masknb]];

We can even make a fairly fast screen recorder from it:

maskWindow[width_, height_, leftMarg_, topMarg_] :=
        WindowSize -> {width, height},
        WindowMargins -> {{leftMarg, Automatic}, {topMarg, 0}},
        Visible -> False]

screenSnapshot[window_] := 

screenRecord = {};
recordingFlag = True;
        "Click to stop recording:",
            {True -> Framed["Recording"], False -> Framed["Stopped  "]}

        masknb = maskWindow[500, 300, 300, 200];
            screenRecord = Join[screenRecord, {screenSnapshot[masknb]}]
screenRecord = Image /@ screenRecord;

MMA screen recorder

  • $\begingroup$ Extremely Fast!!!!! Very impressive answer~ xie xie la~ but still, are there faster methods? $\endgroup$ – Wjx Aug 25 '16 at 14:25
  • $\begingroup$ @Wjx Thanks! For better performance, I'd go win API + NETLink. $\endgroup$ – Silvia Aug 26 '16 at 8:51

In v11.2 you can just use CurrentScreenImage[].


Confirming @R.M's answer (WinXP, Mac OSX 10.8)

enter image description here

  • 1
    $\begingroup$ why not a comment? Also, why are you hiding your porn tabs? ;) $\endgroup$ – rm -rf Aug 11 '12 at 23:44
  • $\begingroup$ @rm -rf The porn tabs are there ... look again $\endgroup$ – Dr. belisarius Aug 11 '12 at 23:45
  • 1
    $\begingroup$ @belisarius Nest[GUIScreenShot[], "", 10] $\endgroup$ – s0rce Aug 12 '12 at 3:29
  • 1
    $\begingroup$ @belisarius It's not a Droste effect until it is. $\endgroup$ – rm -rf Aug 12 '12 at 11:57
  • 1
    $\begingroup$ The Droste Effect: Dynamic[Export["C:\\droste.png", GUIScreenShot[]]; Style[GUIScreenShot[], Magnification -> 1], UpdateInterval -> 3]. When the Dynamic object is not visible, it is not updated (it is sufficient just to reduce the Mathematica window). $\endgroup$ – Alexey Popkov Aug 12 '12 at 18:33

Using JLink,you can do this

robotclass = JavaNew["java.awt.Robot"];
screenSize = Toolkit`getDefaultToolkit[]@getScreenSize[];
image = robotclass@createScreenCapture[JavaNew["java.awt.Rectangle", 0, 0, screenSize@width, screenSize@height]];
ImageIO`write[image, "png",JavaNew["java.io.File", FileNameJoin[{Directory[], "test.png"}]]];


enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.