Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I tried using DISPLAY=:0 import -window root "$HOME/Pictures/screenshot.png" (import is part of the ImageMagick suite), but that just displays a black screen.

I want to do this as I wanted to automate opening an app and taking screenshots of it in different languages, and to change languages, I need to restart lightdm. therefore, run on a tty so your script continues running...

share|improve this question
add comment

3 Answers 3

Try using shutter

DISPLAY=:0 shutter -f -e -n -o "$HOME/Pictures/screenshot.png"

import wont work, because the root window is not in use. Composting "bypasses" it (each window is rendered in it's own buffer then multiplexed to the display, instead of the old way, where they were all rendered on the "root" window).

In addition you need to make sure the VTY is active before you take the screen shot. So For example.

#!/bin/bash
X :1 &
export DISPLAY=:1
sleep 10 # give time for X to start
gedit &
sleep 10 # give time for app to do something
chvt 8 # ensure the X display is active
shutter -f -e -n -o "$HOME/Pictures/screenshot.png" # screenshot
killall xorg # terminate X

share|improve this answer
    
Nope, still giving a black screen :( –  YatharthROCK Dec 8 '12 at 16:35
    
Are you in the X session (on a monitor) when you do this. I just tried and it worked quite well. You will need to be logged in, and have the X session in the active VTY. –  coteyr Dec 9 '12 at 0:38
    
I want a script launched in the tty to be able to do this. –  YatharthROCK Dec 9 '12 at 14:34
    
Yes, but do you switch to the X session before taking the screen shot. X :0 & sleep 50 && sudo chvt 6 && program & sleep 5 && screenshot (notice totally fake script). –  coteyr Dec 9 '12 at 16:14
    
Also just to make sure were talking the same thing you want VT0 (or something) not a screen shot of a text console. So your running the script from a TTY trying to screen shot X (VTY). Is that correct? –  coteyr Dec 9 '12 at 16:16
show 2 more comments

Here is solution using xwd, which is is available in almost all Xorg installations:

 xwd -root -out screenshot.xwd

The screenshot.xwd file can be opened with GIMP:

For more info see http://www.x.org/wiki/UserDocumentation/GettingStarted/.

share|improve this answer
add comment
up vote 1 down vote accepted

Here's what worked for me.

chvt 7
DISPLAY=:0 import -window root "$HOME/Pictures/screenshot.png
chvt 1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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