41

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)?

0

11 Answers 11

47

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.

6
  • 4
    You can also click on a window after import ss.png in order to take a screenshot of that window. May 4, 2019 at 14:34
  • This doesn't work from i3 config, however. Minimal example: add line bindsym $mod+shift+s exec import ~/screenshot.png to your config. Doesn't do anything for me.
    – Chris_128
    Jan 30, 2021 at 9:42
  • See the other answer about flameshot. That's what I'm using these days.
    – casey
    Jan 31, 2021 at 18:47
  • 3
    @Chris_128 You have to use --release flag, ex bindsym --release Print exec import ~/screenshot.png. Check here for explanation as to why i3wm.org/docs/userguide.html Apr 20, 2021 at 21:15
  • 1
    @Chris_128 Yeah sorry Print stands for printscr key. That's just the personal keybinding I use. Apr 26, 2021 at 17:45
22

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/"
1
  • This works great & a great solution it is without any extra heavy tools it works perfectly. Thanks a lot Jan 5, 2023 at 21:04
19

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.

You can edit config in here ~/.config/i3/config and reload the config using i3-msg reload.

1
  • nice tool i was looking for such a tool to make some documentation. Even you can add marking to the screenshot
    – Santhosh
    Apr 21, 2020 at 11:02
8

have you tried scrot a, simple commandline screen capture utility

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

1
  • 1
    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, 2017 at 19:13
7

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!

3

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).

2
  • (1) What is “slop”? (2) What, exactly, is it better than? (3) Why? Nov 7, 2017 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, 2017 at 16:41
2

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.

1
  • 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, 2018 at 18:00
2

Slightly edited the solution by @ddnomad above, here's the bash version of the script with more explicity and another flag that allows saving only to clipboard.

#! /bin/bash -

help_and_exit() {
  cat <<-EOF
  Usage: scregcp [-h|-s|-c] [<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
    -c   - save only to clipboard
EOF
    exit 0
}

base_folder="./"
savefile=true
region=false
params="-window root"
while test $# -gt 0; do
  case "$1" in
    -h|--help*)
      help_and_exit
      ;;
    -r|--region*)
      params=""
      shift
      ;;
    -c|--clipboard-only*)
      savefile=false
      shift
      ;;
    *)
      if [[ $1 =~ ^\- ]] ; then
        echo "error: unknown flag '$1'"
        help_and_exit
      fi
      base_folder="${1}"
      shift
      ;;
  esac
done

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}

if [ "$savefile" = false ] ; then
  rm ${file_path}
fi

Then this is what you add to i3 config:

bindsym --release Shift+Print exec --no-startup-id "/dir/to/script.sh -r $HOME/Pictures/screenshots/"                                   
bindsym --release Control+Shift+Print exec --no-startup-id "/dir/to/script.sh -r -c $HOME/Pictures/screenshots/"                        
bindsym --release Print exec --no-startup-id "/dir/to/script.sh $HOME/Pictures/screenshots/"                                            
bindsym --release Control+Print exec --no-startup-id "/dir/to/script.sh -c $HOME/Pictures/screenshots/"                                 

So the keybinding is:

  • PrtSc = make a screenshot
  • +Control = only save to clipboard
  • +Shift = only capture a specific region of the screen
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

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
1
Feature Shortcut
Full Screen PrtScrn
Selection Shift + PrtScrn
Active Window Super + PrtScrn
Clipboard Full Screen Ctrl + PrtScrn
Clipboard Selection Ctrl + Shift + PrtScrn
Clipboard Active Window Ctrl + Super + PrtScrn

Requirements

  • maim
  • xclip
  • xdotool

Set-up

Set this on your i3 config file ~/.i3/config.

## Screenshots
bindsym Print exec --no-startup-id maim "/home/$USER/Pictures/$(date)"
bindsym $mod+Print exec --no-startup-id maim --window $(xdotool getactivewindow) "/home/$USER/Pictures/$(date)"
bindsym Shift+Print exec --no-startup-id maim --select "/home/$USER/Pictures/$(date)"

## Clipboard Screenshots
bindsym Ctrl+Print exec --no-startup-id maim | xclip -selection clipboard -t image/png
bindsym Ctrl+$mod+Print exec --no-startup-id maim --window $(xdotool getactivewindow) | xclip -selection clipboard -t image/png
bindsym Ctrl+Shift+Print exec --no-startup-id maim --select | xclip -selection clipboard -t image/png

source: https://dev.to/dianjuar/i3wm-screenshot-shortcuts-3n7b

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .