On Lubuntu 18.04, I am trying to take a screenshot of the current focused window. I am using import
from Imagick following https://stackoverflow.com/a/32165476.
It fails in a tab of lxterminal
$ import -window "$(xdotool getwindowfocus -f)" /tmp/file.png
import-im6.q16: unable to read X window image `31457284': Resource temporarily unavailable @ error/xwindow.c/XImportImage/4982.
import-im6.q16: missing an image filename `/tmp/file.png' @ error/import.c/ImportImageCommand/1287.
it succeeds in a xterm window
$ import -window "$(xdotool getwindowfocus -f)" /tmp/file.png
$
Do you know why the problem happens? How can I solve the problem? Thanks.
#!/bin/sh echo "Enter the name of the window:" read window window_id=`xwininfo -name $window | awk '{print $4}' | grep -i 0x` import -window $window_id $window.jpg
Like I said before, this doesn't work completely, but I thought I'd post it anyway. I've gotten it to work for small programs like Calculator, Dictionary, Atomix... nothing like Firefox, gedit, etc. . If you try to do it for larger programs, you'll actually get an error of the following sort:
import: unable to read X window image `0x3200efb': Resource temporarily unavailable.
I think this arises from the fact that these programs actually yield multiple window IDs:
dill@LAMP:~$ xwininfo -tree -root | grep gedit | awk '{print $1}' 0x3000071 0x3000003 0x3000001 0x300001e