How to get a screenshot of only one window from the command line if I have window id? enter image description here

I want to show a preview screen like this for a specific window with qml and pyqt5. What can I do then?

  • Several options, using one of the applications that has this as a cli option, using imagemagick's import or using Gdk in one of the languages. What is the context? – Jacob Vlijm Jan 19 at 16:35
  • @Jacob Vlijm now I added more details. What can I do with this case? – Newtron Malayalam Jan 19 at 17:01
  • Ah, writing a preview application? I hope I can find the time to write an answer in the next few days. In the meantime, have a look here: github.com/UbuntuBudgie/budgie-extras/blob/master/…, line 202-204 are the relevant lines. it's Vala, but the python way is similar. You can do the scaling in one step, and this is the least consuming way. Hope it is understandable. As said, If I can find time in the next few days, I'll write an answer. – Jacob Vlijm Jan 19 at 18:25
  • select the window using xdotool . $id I got from name .delay is optional though advisable or put a wait command in after it. . ids=$(xdotool search --desktop 0 --class "$name") and if more than one id you need to make a decision xdotool windowactivate --sync $id key --delay 100 then use screenshot of that active window gnome-screenshot -w make a script and a keyboard shortcut. – pierrely Jan 24 at 5:47

You can raise the relevant window with the wmctrl command and take its screenshot using the gnome-screenshot command. For example, assuming that the window id is 0x02600010, you can use:

wmctrl -i -a 0x02600010 && gnome-screenshot -w
  • sorry. I didn't describe what I want. Now I edited my post. Can you give me a suitable answer? – Newtron Malayalam Jan 19 at 17:04

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.