Furor Teutonicus
https://www.furorteutonicus.eu/2019/12/27/screenshot-tools-for-linux/
Export date: Sat Jul 4 9:51:40 2020 / +0000 GMT

Screenshot tools for Linux


(This article is meant for intermediate and advanced Linux users.)

To quickly make screenshots, I consider these popular screenshooter tools:

  • xfce4-screenshooter

  • scrot


Because I use XFCE with Arch Linux, I prefer lightweight, fast tools, without loads of dependencies. I also like to autosave screenshots without bothering with questions and user dialog screens. In this blogpost, I will compare a few main features and test the speed of these two utilities. Note that there are many more screenshoters 1. The screen capture program maim 2 is intended to improve on scrot. While scrot 3 is old, it is fast and gets the job done. Also there is a resurrecting 4 project, which Arch 5 uses. For XFCE users, xfce4-screenshooter is part of xfce4-goodies.

The often recommended shutter tool is less ideal for XFCE as it depends on gnome-vfs in the AUR. The predecessor of shutter was called gscrot and was a perl-based frontend for scrot. It seems shutter still is such a frontend, and has a lot of perl dependencies. I wanted to try it from AUR but got a build error in the libwnck+ dependency, so I gave up because it seems shutter does not satisfy my need for a tool with minimal depedencies for XFCE.

Both tools can grab the whole screen, the active screen (in focus), a custom part of the screen, and save the file. Only xfce4-screenshooter can also copy the screenshot to the clipboard; scrot has no option for that. For scrot, that can be solved by using the --exec option combined with the xclip tool. An advantage of scrot is that it can use modifyers for the output filename; so you can use the date and time and other variables in the filename. An advantage of xfce4-screenshooter is the nice dialog it can show if no options are given on the command line.

Examples


Make a screenshot of the whole full screen.
xfce4-screenshooter --fullscreen
scrot --multidisp

Make a screenshot of the active windows in focus.
xfce4-screenshooter --window
scrot --focused --border

Note: The --border option for scrot is optional; it includes the border drawn by the Windows Manager.

Select and store a custom region (rectangle).
xfce4-screenshooter --region
scrot --select

Combined versions: for the active window; copy to clipboard, save to file.
xfce4-screenshooter --window --clipboard --save OUTPUT.png
scrot --focused --border --exec 'xclip -selection clipboard -target image/png -in $f' OUTPUT.png

Speed comparison


The last example above, the combined versions, were tested using time. The xfce4-screenshooter took 0.39 seconds on the 2nd run; the scrot version took 0.10 seconds on the second run. (I tested it for the second run to include caching effects. The first match was also won by scrot.) Clearly scrot is the winner for quick, no-dialog scenarios.

My preferred command


Let's copy the screenshot itself to the clipboard, and the filename to the “primary” buffer“. To learn more about”primary" and “clipboard”, see clipboards-spec 6 and this question 7. Also scrot's ability to include variables in the output filename, and it being desktop agnostic, makes it perfect for automated use.
scrot --focused --border --exec 'xclip -selection clipboard -target image/png -in $f; echo -n "$f" | xclip -selection primary' '%Y-%m-%dT%H.%M.%S_screenshot.png'

Even better would be to include the window title of the active window, but that would complicate matters as you need to filter out illegal characters and so forth. Still it can be done in a reasonable manner:
xdotool getwindowfocus getwindowname | tr -c '4060-71101-132141-172' '_'

To have the full experience, I decided to use a shellscript. See screenshot.sh 8 (click on the link to download).
#!/bin/sh

STORE="/home/evert/Pictures/screenshots"
EMAIL="post@evert.net"

# -------------
# Makes screenshots, optionally mails them.
# Evert Mouw, 2019-12-27

DEPENDENCIES="scrot xclip xfce4-screenshooter notify-send mail"
for D in $DEPENDENCIES; do
if ! which $D > /dev/null; then
echo "$D not found"
exit 1
fi
done

if ! [ -d "$STORE" ]; then
MSG="$STORE is not a directory."
echo "$MSG"
notify-send --icon=error "screenshooter" "$MSG"
exit 1
fi

if ! [ -w "$STORE" ]; then
MSG="$STORE is not writable!"
echo "$MSG"
notify-send --icon=error "screenshooter" "$MSG"
exit 1
fi

FG=$(xdotool getwindowfocus getwindowname | tr -cs '60-71101-132141-172' '_' | cut -c 1-33)
ME="$(whoami)@$(hostname -s)"

case $1 in
region|select)
OPTIONS="--select --freeze --line style=dash,width=3"
OUTNAME="$STORE/%Y-%m-%dT%H.%M.%S_$FG.part"
break
;;
active|focused)
OPTIONS="--focused --border"
OUTNAME="$STORE/%Y-%m-%dT%H.%M.%S_$FG"
break
;;
fullscreen|full)
OPTIONS="--multidisp"
OUTNAME="$STORE/%Y-%m-%dT%H.%M.%S_$ME.full"
break
;;
custom)
xfce4-screenshooter
exit 0
break
;;
*)
echo "Whut?"
exit 1
esac

scrot $OPTIONS --exec 'xclip -selection clipboard -target image/png -in $f; echo -n "$f" | xclip -selection primary' "$OUTNAME.png"

if [ "$?" -ne "0" ]; then
MSG="Some error occurred.nOUTNAME=$OUTNAMEnACTION=$1"
echo -e "$MSG"
notify-send --icon=warn "screenshooter" "$MSG"
exit 1
fi

OUTFILE=$(xclip -selection primary -out)
notify-send --icon=info "screenshooter" "Screenshot saved as $OUTFILE"

case $2 in
'')
# silently ignore
break
;;
mail)
echo "Screenshot" | mail -s screenshot -a "$OUTFILE" $EMAIL
break
;;
*)
echo "2nd argument not recognized"
exit 1
esac

Keyboard shortcuts


I propose to use the same keyboard shortcuts as the free, open source Greenshot 9 tool for Windows. In addition, I use the Super key (Windows key) to launch a custom dialog.

  • region: PrnScn

  • window: Alt-PrnScn

  • fullscreen: Ctl-PrnScn

  • custom: Super-PrnScn


To keep consistency, I personally set the same keyboard shortcuts in XFCE.
xfconf-query --create --channel xfce4-keyboard-shortcuts --property "/commands/custom/Print" --type string --set "sh -c 'sleep 0.1 && /home/evert/bin/screenshot.sh region'"
xfconf-query --create --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Alt>Print" --type string --set "/home/evert/bin/screenshot.sh active"
xfconf-query --create --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Ctl>Print" --type string --set "/home/evert/bin/screenshot.sh full"
xfconf-query --create --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Super>Print" --type string --set "/home/evert/bin/screenshot.sh custom"

Note that the first line contains a workaround 10 (see also here 11) for a bug 12 #616608 in scrot.

To see currently assigned PrnSrn keys:
xfconf-query -c xfce4-keyboard-shortcuts -lv | grep -i Print

Finally


This works for me. For a discussion on screenshooters, see e.g. on the forum of Linux Mint 13.

screenshot
Editing screenshot.sh and making a screenshot using that script and scrot.
Excerpt: Using the scrot screenshooter tool in XFCE using a schellscript. For advanced Linux users.
Links:
  1. https://wiki.archlinux.org/index.php/Screen_captur e
  2. https://github.com/naelstrof/maim
  3. https://en.wikipedia.org/wiki/Scrot
  4. https://github.com/resurrecting-open-source-projec ts/scrot
  5. https://www.archlinux.org/packages/community/x86_6 4/scrot/
  6. https://specifications.freedesktop.org/clipboards- spec/clipboards-latest.txt
  7. https://superuser.com/questions/200444/why-do-we-h ave-3-types-of-x-selections-in-linux
  8. https://www.furorteutonicus.eu/wp-content/uploads/ 2019/12/screenshot.zip
  9. https://getgreenshot.org/
  10. https://forum.xfce.org/viewtopic.php?id=12962
  11. https://bbs.archlinux.org/viewtopic.php?id=143065
  12. https://groups.google.com/forum/#!topic/linux.debi an.bugs.dist/_tmJIFYBfZo
  13. https://forums.linuxmint.com/viewtopic.php?t=16720 8
Post date: 2019-12-27 19:19:44
Post date GMT: 2019-12-27 18:19:44

Post modified date: 2019-12-27 19:51:28
Post modified date GMT: 2019-12-27 18:51:28

Export date: Sat Jul 4 9:51:40 2020 / +0000 GMT
This page was exported from Furor Teutonicus [ https://www.furorteutonicus.eu ]
Export of Post and Page has been powered by [ Universal Post Manager ] plugin from www.ProfProjects.com