The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

Screenshot of focused window

asked Oct 21 '14

Kaligule gravatar image

I want to be able to do screen shots of the focused by pressing a button. Should be easy.

First try: scrot

(since it seems to be the most recomended tool for screenshots in i3wm)

Whole screen

bindsym XF86Display exec "scrot ~/Downloads/Screenshot%Y-%m-%d%H:%M:%S.png"

Works fine

Focussed Window

Well... Some people in the internet seem to think there is a -u flag for scrot but in the yum-installed Fedora version (0.8) there definitely is not. Bad luck.

Second try: ImageMagick

(since many people tell me it can do anything I want)

Whole screen

bindsym XF86Display exec "import -window root ~/Downloads/Screenshot$(date +%F%H:%M:%S).png"

The date is not as elegant as in scrot, works fine though.

Focussed window

Tricky. I don't know the id of the focused window. But there is a workaround:

import -window xwininfo | awk '/.*Window id:.*/ {print $4}' ~/Downloads/Screenshot$(date +%F%H:%M:%S).png

I can click on the window I want to screenshot and there we go. A bit of a hack (found here: http: //www .trueelena.org/computers/howto/screenshotswithimagemagick.html ), but anyway. Works in the console. But in i3config:

bindsym XF86Display exec "import -window xwininfo | awk '/.*Window id:.*/ {print $4}' ~/Downloads/Screenshot$(date +%F%H:%M:%S).png"

Doesn't work. I am asked to click on a window, but no screenshot is saved. I am not sure why.

Could someone give me a hand, please?

3 answers

Sort by » oldest newest most voted
0

answered Oct 8 '15

SpicyCat gravatar image

ksnapshot

Check my answer to another similar question

0

answered Sep 30 '15

When I use:

$scrot --version
scrot version 0.8

you get the -u flag which:

-u, --focused use the currently focused window

and doing:

~$ scrot -u '%Y%m%d_%H%M%S.png' -e 'mv $f ~/images/shots/'

Does in fact create a screeshot of the currently focused window and sends it to the /shots/ directory.

For further reference -s:

-s, --select              interactively choose a window or rectangle
                               with the mouse

That is th option that I prefer

0

answered Oct 21 '14

cee gravatar image

I rarely use screenshots.
But when I do, I use scrot, select the region I want and open gimp.
That all with one keyboard shortcut. What's not to love about i3 ;-)

bindsym Mod1+Print exec scrot -s -e 'mv $f /tmp/ && gimp /tmp/$f' --release

Or for the whole screen

bindsym Ctrl+Print exec scrot -e 'mv $f /tmp/ && gimp /tmp/$f'

Disclaimer:
The two lines are shamelessly taken from another entry in this forum.

Comments

This is ok, but doesn't solve the problem of screenshoting exactly 1 window. I don't want to select a region, but shoot the active window.

Kaligule gravatar imageKaligule (Oct 22 '14)edit

Yes, that is true. But as I said I rarely use screenshots and so this is sufficient for me.

cee gravatar imagecee (Oct 22 '14)edit

Question Tools

Stats

Asked: Oct 21 '14

Seen: 1,203 times

Last updated: Oct 08