Skip to content

Instantly share code, notes, and snippets.

@stbuehler
Created September 24, 2021 07:36
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 stbuehler/370ddbed646ff4f4c6fbe336e613154b to your computer and use it in GitHub Desktop.
Save stbuehler/370ddbed646ff4f4c6fbe336e613154b to your computer and use it in GitHub Desktop.
scrot to clipboard with automatic cleanup
#!/bin/sh
# example config for i3 (.config/i3/config):
# # select window with mouse
# bindsym Print exec --no-startup-id scrot-xclip.sh --select --freeze
# # current window
# bindsym $mod+Print exec --no-startup-id scrot-xclip.sh --focused
set -e
tmpdir=$(mktemp --tmpdir -d scrot-xclip-XXXXXXX)
trap 'rm -rf "${tmpdir}"' EXIT
setxkbmap -option grab:break_actions
xdotool key XF86Ungrab
scrot "$@" "${tmpdir}"/'screenshot-%Y-%m-%d_%H:%M:%S.png' -e \
'exec xclip -quiet -t image/png -selection clipboard -i $f'
echo "Clipboard got overwritten"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment