Created
May 25, 2020 22:55
-
-
Save Niols/8c60eb687c6c0d2beab1ae3ec302bfc2 to your computer and use it in GitHub Desktop.
Draft of screenshoting script that also copies the output to clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
readonly PROGNAME=$(basename "$0") | |
help () { | |
cat <<EOF | |
Usage: $0 [OPTIONS] | |
Options can be: | |
--select interactively select area | |
--no-select do not interactively select area (default) | |
--freeze freeze when selecting area (default) | |
--no-freeze do not freeze when selecting area | |
--help print this help and exit | |
EOF | |
} | |
error () { | |
rc=$1; shift; | |
error=$(printf -- "$@") | |
echo "$error" >&2 | |
help | |
notify-send "$PROGNAME error $rc" "$error" || true | |
exit "$rc"; | |
} | |
## Read command line | |
SELECT= | |
FREEZE=--freeze | |
while [ $# -gt 0 ]; do | |
case $1 in | |
--select) | |
SELECT='--select' | |
;; | |
--no-select) | |
SELECT= | |
;; | |
--freeze) | |
FREEZE='--freeze' | |
;; | |
--no-freeze) | |
FREEZE= | |
;; | |
--help) | |
help | |
exit 0 | |
;; | |
*) | |
error 2 'Unknown argument: %s\n' "$1" | |
esac | |
shift | |
done | |
## Find scrot and xclip | |
command -v scrot >/dev/null || error 3 'Could not find scrot.\n' | |
command -v xclip >/dev/null || error 3 'Could not find xclip.\n' | |
## Try to load XDG configuration. | |
readonly USER_DIRS="${XDG_CONFIG_HOME:-$HOME/.config}"/user-dirs.dirs | |
if [ -f "$USER_DIRS" ]; then | |
. "$USER_DIRS" | |
fi | |
## Try to get XDG pictures directory. Default to home. | |
if [ -n "$XDG_PICTURES_DIR" ]; then | |
TARGET=$XDG_PICTURES_DIR/Screenshots | |
else | |
TARGET=$HOME | |
fi | |
mkdir -p "$TARGET" | |
## The following is a dirty hack to get scrot to work from i3 bindings. | |
## See https://bbs.archlinux.org/viewtopic.php?id=86507 | |
sleep .1 | |
## Take the picture. | |
scrot \ | |
$SELECT \ | |
$FREEZE --line style=dash,width=3 \ | |
--exec 'xclip -target image/png -selection clipboard $f' \ | |
"$TARGET"/'%Y-%m-%d_%H-%M-%S'.png \ | |
2>&1 \ | |
notify-send "$PROGNAME" "Screenshot saved." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment