Skip to content

Instantly share code, notes, and snippets.

@ceving
Created February 1, 2024 16:44
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 ceving/4e674ae690688a2181756ec5afe3b1af to your computer and use it in GitHub Desktop.
Save ceving/4e674ae690688a2181756ec5afe3b1af to your computer and use it in GitHub Desktop.
Bash script to take a screenshot
#! /bin/bash
set -eu
usage() { echo "Usage: $0 [-w WAIT] [PNGFILE]" 1>&2; }
while getopts "w:h" o; do
case "${o}" in
w) wait=$((OPTARG));;
h) usage; exit 0;;
*) exit 1;;
esac
done
shift $((OPTIND-1))
if (( ${wait:-0} > 0)); then
sleep $wait
fi
if (( $# > 0 )); then
exec > "$1"
fi
xwd | convert xwd:- png:-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment