Raspberry Pi: take a screenshot from a display with no keyboard and mouse
The Raspberry Pi in the kitchen runs relatively stable, but recently the browser (which is showing the openHAB HABpanel) popped up a warning in the upper right corner. That's annoying, because this area in HABpanel shows the outside temperature.
Before investigating what's going on, I had to figure out a way to get a screenshot of the display - without running into the kitchen with my mobile phone. And without attaching a keyboard all the time (to press the "Print" button).
The system is running Raspbian. The display manager is LXDE. Raspbian comes with a screenshot tool preinstalled: "scrot". The nice thing about it: I can take a screenshot from the commandline, while logging in over ssh.
All I had to do was to teach "scrot" where the display is. If you start it without any display settings, it can't connect to the X Server:
pi@raspberrypi:~ $ scrot giblib error: Can't open X display. It is running, yeah?
The following environment variables need to be set: "DISPLAY" (pointing to the first display, which is "0"), and "XAUTHORITY" (pointing to the Xauthority file of the currently logged in user):
export DISPLAY=:0 export XAUTHORITY=/home/pi/.Xauthority
Both variables need to be exported, which in shell terminology means: any started program can see the environment variable as well. Otherwise it's just a variable for the shell itself.
After setting the two variables, I can take a screenshot:
pi@raspberrypi:~ $ scrot pi@raspberrypi:~ $ ls -ld *.png -rw-r--r-- 1 pi pi 31411 Feb 10 00:42 2020-02-10-004250_800x480_scrot.png
Display comments as Linear | Threaded