LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to take a screenshot of a window that is not visible in batch mode? (https://www.linuxquestions.org/questions/linux-software-2/how-to-take-a-screenshot-of-a-window-that-is-not-visible-in-batch-mode-4175627421/)

FlinchX 04-11-2018 03:01 AM

How to take a screenshot of a window that is not visible in batch mode?
 
What have I tried so far:

- import from imagemagick reports an error for both window id and window name

- scrot doesn't accept a window id as argument

- maim and xwd don't take the screenshot if the window is not visible (it's on
another workspace, not the active one, i'm using vanilla dwm)

Note: I take window id and name from the output of wmctrl -l

keefaz 04-11-2018 07:17 AM

Maybe make window sticky, then unstick it with wmctrl?
Not tested (wmctrl not installed here)
Code:

wmctrl -i -r <window id> -b add,sticky
import -window <window id> window_image.png
wmctrl -i -r <window id> -b remove,sticky


allend 04-11-2018 08:52 AM

I can get this to work with my dual monitor setup with separate screens on Monitor0 and Monitor1.
From a terminal on Monitor1, I can capture an image from a window displayed on Monitor0 with
Code:

import -display ':0.0' -window 0x1600059 ~/Desktop/wsnapshot.png
As 'man import' states:
Quote:

import - saves any visible window ...
If you have only one screen, then the window to be captured and the terminal where the command is issued will both need to be visible on the screen, otherwise the errors reported will occur.

FlinchX 04-11-2018 09:37 AM

Quote:

Originally Posted by keefaz (Post 5841820)
Maybe make window sticky, then unstick it with wmctrl?
Not tested (wmctrl not installed here)
Code:

wmctrl -i -r <window id> -b add,sticky
import -window <window id> window_image.png
wmctrl -i -r <window id> -b remove,sticky


What are the implications of this and what exactly is a sticky window? I don't want this to interfere into my workflow that happens in other windows (which are in other workspaces).

FlinchX 04-11-2018 09:40 AM

Quote:

Originally Posted by allend (Post 5841854)
import - saves any visible window ...

Bummer. Definitely missed it when reading the manpage.

Quote:

Originally Posted by allend (Post 5841854)
If you have only one screen, then the window to be captured and the terminal where the command is issued will both need to be visible on the screen, otherwise the errors reported will occur.

I do have just one screen indeed. But import from imagemagick is not a mandatory requirement. I'd be happy to use any other CLI tool that will allow me to take screens of windows that are not visible.

teckk 04-11-2018 11:45 AM

You can't take a screenshot of a window that does not exist.
If the window is not visible then there is no window. Maybe you should explain further what you are wanting. To capture the output form a running program/process? Screenshot is just that, a picture of something that is on the screen. Maybe you are wanting something else.

I'm trying to figure out what you are doing. A shot of a minimized window? Or do you have a dual monitor setup with one monitor unplugged? Why isn't the window visible? Or a window that is behind another window? What?

keefaz 04-11-2018 11:49 AM

Quote:

Originally Posted by FlinchX (Post 5841868)
What are the implications of this and what exactly is a sticky window? I don't want this to interfere into my workflow that happens in other windows (which are in other workspaces).

A sticky window is a window visible on all workspaces

teckk 04-11-2018 12:08 PM

If you are wanting to capture a window on another work space, then give yourself a pause so you can make it active.
Code:

sleep 5 && scrot -u
or
scrot -ud 5

https://askubuntu.com/questions/2117...ces-or-windows
https://askubuntu.com/questions/3030...nactive-window
https://unix.stackexchange.com/quest...tive-workspace

FlinchX 04-11-2018 12:37 PM

Quote:

Originally Posted by teckk (Post 5841919)
You can't take a screenshot of a window that does not exist.
If the window is not visible then there is no window. Maybe you should explain further what you are wanting. To capture the output form a running program/process? Screenshot is just that, a picture of something that is on the screen. Maybe you are wanting something else.

I'm trying to figure out what you are doing. A shot of a minimized window? Or do you have a dual monitor setup with one monitor unplugged? Why isn't the window visible? Or a window that is behind another window? What?

I want to take a screenshot of a window that is identified by an id, but is not visible on screen - it's on another workspace (dwm calls these workspaces tags and I switch between them using Alt+1, Alt+2 and so on).

FlinchX 04-11-2018 12:39 PM

Quote:

Originally Posted by keefaz (Post 5841925)
A sticky window is a window visible on all workspaces

That's what I'm trying to avoid: I don't want the window I'm trying to take a screenshot of to appear on the active workspace.

FlinchX 04-11-2018 12:43 PM

Quote:

Originally Posted by teckk (Post 5841944)
If you are wanting to capture a window on another work space, then give yourself a pause so you can make it active.

That would defeat the point of what I'm trying to achieve. I can just stick to the workspace where the window in question is, but then
I can't do anything else, because I need to take lots of screens for hours. That's why I want to run that window in the background (another workspace) and I need a way to take screenshots of it.

Quote:

Originally Posted by teckk (Post 5841944)
Code:

sleep 5 && scrot -u
or
scrot -ud 5


My manpage for scrot has a -d option, but no -u uption. I'm using scrot-0.8

keefaz 04-11-2018 01:39 PM

Quote:

Originally Posted by FlinchX (Post 5841956)
That's what I'm trying to avoid: I don't want the window I'm trying to take a screenshot of to appear on the active workspace.

The idea was to make the window appear just the time to do the screenshot and then put it back in workspace where it belongs...

FlinchX 04-11-2018 02:19 PM

Quote:

Originally Posted by keefaz (Post 5841992)
The idea was to make the window appear just the time to do the screenshot and then put it back in workspace where it belongs...

The idea is not good, because dwm is a tiling wm, and the window might change size/position while appearing on another workspace.

keefaz 04-11-2018 02:54 PM

Technically changing window state to sticky does not move it. On the contrary, it's a flag that tells to window manager to let the window stay in place (stick on screen) while other element can move (viewports...)

Maybe dwm doesn't support this feature though (I never used it)

allend 04-11-2018 05:31 PM

This is the command that I use to take window snapshots.
Code:

import -window $(xwininfo | awk --non-decimal-data '/Window id/{printf "%d", $4}') ~/Desktop/wsnapshot.png
If that is run in a terminal in one work space then you can use keyboard shortcuts to get to another workspace before clicking the mouse to select the window for the snapshot.

I actually usually use it from a script behind a right click menu entry.

PS - The conversion of the window id from hex to decimal does not appear to be necessary for 'import' any more.


All times are GMT -5. The time now is 10:15 AM.