1

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.

Someone has similar script

#!/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

1 Answer 1

2

I'm on Kubuntu 18.04. I tried

$ sleep 5s && import -window "$(xdotool getwindowfocus -f)" ~/Desktop/file.png
import-im6.q16: unable to read X window image `83886084': Resource temporarily unavailable @ error/xwindow.c/XImportImage/4982.
import-im6.q16: missing an image filename `/home/dkb/Desktop/file.png' @ error/import.c/ImportImageCommand/1287.

and

$ sleep 5s && import -window "$(xdotool getactivewindow)" ~/Desktop/file.png
$ 

The latter command which uses xdotool getactivewindow works in konsole (version 17.12.3) and in lxterminal (version 0.3.1).

sleep is to let me switch from the terminal to another application's window. The command catches active windows of Firefox and geany.

As for

Do you know why the problem happens?

I don't really know but searching man xdotool for windowfocus tells us that

Uses XSetInputFocus which may be ignored by some window managers or programs.

Whether that also applies to getwindowfocus isn't explicitly mentioned.

1
  • Thanks. removing -f from my command solve the problem on lxterminal. Not sure why.
    – Tim
    Dec 6, 2018 at 3:09

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.