Skip to content

Instantly share code, notes, and snippets.

@phocean
Last active March 4, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phocean/22cb8d9e51814cfe6d160afdd0fef955 to your computer and use it in GitHub Desktop.
Save phocean/22cb8d9e51814cfe6d160afdd0fef955 to your computer and use it in GitHub Desktop.
Simple wrapper script to take nicer X11 screenshots, that look alike with either SSD or CSD windows.
#!/bin/bash
# Simple wrapper script to take nicer X11 screenshots:
# - uniform appearance whether the target window is using server-side or client-side decorations ;
# - wallpaper and background removed ;
# - shadow effect ;
# - always sending the result to the clipboard.
#
# Prerequisites:
# - X11 environment and basic utilities (xprop, import);
# - *maim* screenshot utility ;
# - *xdotool* ;
# - *xclip* ;
# - *imagemagick* tools (convert) ;
# - libnotify along with the *notify-send* command ;
#
# All these should be installed by default on most Linux distributions or just one install command away from the standard repositories.
# Note that it will not work with environments using Wayland.
set -e
PATH=$(/usr/bin/getconf PATH)
function Usage {
echo -e "Usage: $0 {desktop|zone|window} [delay]\n\tdelay: in seconds"
exit 1
}
([[ $# -eq 0 ]] || [[ $# -gt 2 ]]) && Usage
COMMAND=$1
DELAY=${2-0}
[[ $DELAY =~ ^-?[0-9]+$ ]] || Usage
DATE=$(date +%Y%m%d-%H%M%S)
FILENAME=$DATE.png
DEST=$HOME/Images/$FILENAME # SET AT YOUR CONVENIENCE
case $COMMAND in
desktop)
maim -x :0.0 -d $DELAY $DEST
;;
zone)
maim -s -d $DELAY $DEST
;;
window)
NOCSD_PROP="_NET_FRAME_EXTENTS(CARDINAL)"
WINID=$(xdotool selectwindow)
if [[ -z $(xprop -id $WINID | grep $NOCSD_PROP) ]]
then
maim -d $DELAY -i $WINID $DEST
else
import -delay $DELAY -window $WINID -frame $DEST
convert $DEST \( +clone -background black -shadow 40x20+0+0 \) +swap -background none -layers merge +repage $DEST
fi
;;
*)
Usage
esac
xclip -selection clipboard -t image/png $DEST
notify-send -t 5000 -u low -i gnome-screenshot "Screenshot" "$COMMAND, delay = $DELAY sec.\nPicture sent to the clipboard and saved in file: $DEST."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment