27

About a month ago I switched from Ubuntu 14.04 LTS to Arch and I'm quite happy with this decision. However, I miss some features with my new distro, especially Shift+printscr which in Unity allows selection of a screen region to be captured.

I use i3 WM. So, my question is: how can I configure Unity-like screenshot behaviour to be able to snap screen regions or windows with a keyboard shortcut or something (without digging into window id and console stuff)?

29

You can use import, part of ImageMagick.

Capture a region

This will change your cursor into a crosshair and when you click and drag to form a box, that box will be saved as ss.png.

import ss.png

Capture whole display

import -window root ss.png

You can also replace the word root with the window id to capture a specific window.

  • 1
    Simple, perfect, just what I needed - and I didn't have to download another program. – Darren Haynes Mar 24 '17 at 23:06
  • 1
    You can also click on a window after import ss.png in order to take a screenshot of that window. – John Gowers May 4 at 14:34
9

It's been a long time since I'd asked this question and it looks like it's helpful for some of the users. So I provide my own script for making screenshots with xclip and imagemagick packages.

First of all, install the above mentioned dependencies. Then you can do whatever you want with the script below. It supports making a screenshot of a whole screen or a screen region and also it automatically copies a screenshot to a clipboard so you can paste it everywhere (e.i browser or Telegram messenger).

A couple of not so hard to come up with hacks would add a support for capturing specific windows and toggle copying part.

#!/usr/bin/env bash

# screenshots stuff
# TODO: docs

function help_and_exit {
    if [ -n "${1}" ]; then
        echo "${1}"
    fi
    cat <<-EOF
    Usage: scregcp [-h|-s] [<screenshots_base_folder>]

    Take screenshot of a whole screen or a specified region,
    save it to a specified folder (current folder is default)
    and copy it to a clipboard. 

       -h   - print help and exit
       -s   - take a screenshot of a screen region
EOF
    if [ -n "${1}" ]; then
        exit 1
    fi
    exit 0
}

if [ "${1}" == '-h'  ]; then
    help_and_exit
elif [ "${1:0:1}" == '-' ]; then
    if [ "${1}" != '-s' ]; then
        help_and_exit "error: unknown option ${1}"  
    fi
    base_folder="${2}"
else
    base_folder="${1}"
    params="-window root"
fi  

file_path=${base_folder}$( date '+%Y-%m-%d_%H-%M-%S' )_screenshot.png
import ${params} ${file_path}
xclip -selection clipboard -target image/png -i < ${file_path}

And here is my reference shortcuts for an i3wm to make use of this script:

# take a screenshot of a screen region and copy it to a clipboard
bindsym --release Shift+Print exec "scregcp -s /home/ddnomad/pictures/screenshots/"

# take a screenshot of a whole window and copy it to a clipboard
bindsym --release Print exec "scregcp /home/ddnomad/pictures/screenshots/"
6

have you tried scrot a, simple commandline screen capture utility

ref., : https://faq.i3wm.org/question/202/what-do-you-guys-use-for-printscreen/

  • Wow, after googling I realized, that scrot is actually capable of everything I need. Too weird I didn't find it by myself. Thanks, dude! – ddnomad Oct 1 '15 at 19:51
  • you can also use scrot -s to capture a specific region. run the command then click and hold then click on the second point, it'll create a file with date as filename in your current directory. – vimdude Jan 1 '17 at 19:13
5

First, install xclip, imagemagick and jq!

pacman -S imagemagick jq xclip

I have this line in my i3 config:

bindsym $mod+Print exec \
    import -window $( \
        i3-msg -t get_tree | \
        jq 'recurse(.nodes[]) | select(.focused).window' \
    ) png:- | \
    xclip -selection clipboard -t image/png

This will put a screenshot of the active window on your clipboard when you press mod (Window / Alt) + Printscreen.

i3-msg -t get-tree gets all windows from i3 as json, then we use jq to get the window id of the focussed window. We pass it to imagemagicks import command and pipe the result to xclip who will put it on the clipboard!

2

Flameshot is a decent alternative.

bindsym Print       exec flameshot full
bindsym Shift+Print exec flameshot gui

You can use option -p /path/to/directory to skip selecting the save directory.

1

A very simple option if you have it installed or don't mind installing it is using xfce4-screenshooter and i3 config would be:

bindsym Print exec --no-startup-id xfce4-screenshooter

Caveat: although fairly lightweight there are some dependencies if you are not using any other xfce4 programs

1

Use maim. It's more actively developed and depends on slop which is way better.

Don't use scrot.  Its selection box corrupts and leaves an impression in the screenshot (also the box deforms when resizing) when used over an updating window (say htop).

  • (1) What is “slop”? (2) What, exactly, is it better than? (3) Why? – G-Man Says 'Reinstate Monica' Nov 7 '17 at 22:17
  • 1. Select operation, used to select window regions [github.com/naelstrof/slop] 2. It's better than scrot because it doesn't undergo selection box corruption (Try scrot over htop). 3. idk. – Hritik Nov 8 '17 at 16:41
1

I like shutter for its post-processing capabilities (hand-drawn red circles!) and comprehensive configuration options.

You can grab a screen region by running

shutter --select

You can set up key bindings in .config/i3/config like so:

bindsym Print         exec shutter --full
bindsym Shift+Print   exec shutter --select

It takes a second to load, so you may want to autostart it in the background:

exec shutter --min_at_startup

Shutter will be accessible via a tray icon then, which gives you many useful options beyond the above.

  • Shutter can't easily be installed fully on Ubuntu 18.04 at this point in time (edit tool depends on unavailable library; custom PPA not up to date). Sad. – Raphael May 5 '18 at 18:00
1

This perl6 script takes root, area, window, or delay ScreenShots using import and saves them in a $file and in the clipboard.

#!/usr/bin/env perl6
use v6;

sub print_window(Str $file) {
  qx{xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"} ~~ /(0x\S*)/;
  run <import -window>, $0, $file;
}

sub MAIN( Str $option where $option ∈ <root area window delay> ) {
  my $today = DateTime.now( 
    formatter => { 
      sprintf "%04d_%02d_%02d_%02d-%02d-%02d", .year, .month, .day, .hour, .minute, .second 
    } 
  );
  my $file  = "$*HOME/Dades/Imatges/ScreenShots/$today.png";

  given $option {
    when 'root'   { run <import -window root>, $file }
    when 'area'   { run 'import', $file              }
    when 'window' { print_window($file)              }
    when 'delay'  { sleep 10; print_window($file)    }
  }
  run <xclip -selection clipboard -target image/png -i>, $file;
  run <xmessage -nearmouse -timeout 3>, "Screenshot in clipboard, and saved in $today.png";
}

These are the key bindings in i3 to run the script:

bindsym $mod+Print exec Print_Screen root 
bindsym --release $mod+Shift+Print exec Print_Screen area
bindsym $mod+Mod1+Print exec Print_Screen delay
bindsym $mod+Control+Print exec Print_Screen window

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.