LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-11-2018, 03:01 AM   #1
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Rep: Reputation: Disabled
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
 
Old 04-11-2018, 07:17 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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
 
1 members found this post helpful.
Old 04-11-2018, 08:52 AM   #3
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
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.
 
Old 04-11-2018, 09:37 AM   #4
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
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).
 
Old 04-11-2018, 09:40 AM   #5
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
import - saves any visible window ...
Bummer. Definitely missed it when reading the manpage.

Quote:
Originally Posted by allend View Post
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.
 
Old 04-11-2018, 11:45 AM   #6
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,142
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
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?
 
Old 04-11-2018, 11:49 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by FlinchX View Post
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
 
Old 04-11-2018, 12:08 PM   #8
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,142
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
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
 
Old 04-11-2018, 12:37 PM   #9
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by teckk View Post
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).
 
Old 04-11-2018, 12:39 PM   #10
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
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.
 
Old 04-11-2018, 12:43 PM   #11
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by teckk View Post
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 View Post
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
 
Old 04-11-2018, 01:39 PM   #12
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by FlinchX View Post
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...
 
Old 04-11-2018, 02:19 PM   #13
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
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.
 
Old 04-11-2018, 02:54 PM   #14
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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)
 
Old 04-11-2018, 05:31 PM   #15
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
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.

Last edited by allend; 04-11-2018 at 05:37 PM. Reason: Added PS -
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Login window not visible on wakeup. Lubuntu 14.04 wolfson Linux - Desktop 1 02-13-2015 08:50 AM
batch mode mmhs Linux - Newbie 1 09-04-2012 02:51 AM
Running ‘top’ with ‘Irix mode’ off in batch mode alexz1011 Linux - Software 1 10-02-2009 03:29 PM
How to customize KDE so that a window is visible only in one desktop rockor Linux - Desktop 1 08-20-2009 08:38 PM
Using top in batch mode neothephoenix Linux - Server 5 06-09-2007 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration