Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Last active October 9, 2015 14:15
Show Gist options
  • Save marek-saji/3d3061c6bdd9da323d05 to your computer and use it in GitHub Desktop.
Save marek-saji/3d3061c6bdd9da323d05 to your computer and use it in GitHub Desktop.
Select area on the screen and record it as a GIF
#!/bin/sh
# Select area on the screen and record it as a GIF.
# Running for the second time stops recording, so it's suitable for
# assigning to a key.
set -e
getbin ()
{
BIN="$( which "$1" || which "$( dirname "$0" )/$1" )"
if [ -z "${BIN}" ]
then
"$( which xmessage || echo echo )" "ERROR No $1 binary found."
exit 70
fi
echo "${BIN}"
}
SCRIPT_DIR="$( dirname "$0" )"
# https://github.com/GNOME/byzanz
# https://launchpad.net/~fossfreedom/+archive/ubuntu/byzanz
BYZANZ_BIN="$( getbin byzanz-record )"
# Get source from
# https://web.archive.org/web/20140914024847/https://bbs.archlinux.org/viewtopic.php?id=85378#p660547
# compile with and place in the same directory as this script:
# gcc -Wall xrectsel.c -o …/xrectsel -lX11
XRECTSEL_BIN="$( getbin xrectsel )"
OUT_DIR="$( xdg-user-dir VIDEOS || echo "$HOME" )"
OUT_FN="recording$( date +%FT%T ).gif"
rec_stop ()
{
killall "$( basename "${BYZANZ_BIN}" )"
}
rec_start ()
{
# When assigned to a key in GNONE, displays
# "couldn't grab keyboard:" before geometry
GEO="$( "${XRECTSEL_BIN}" | sed 's/^.*://' )"
WIDTH="$( echo "${GEO}" | cut -dx -f1 )"
HEIGHT="$( echo "${GEO}" | cut -dx -f2 | cut -d+ -f1 )"
X="$( echo "${GEO}" | cut -d+ -f2 )"
Y="$( echo "${GEO}" | cut -d+ -f3 )"
"${BYZANZ_BIN}" \
--delay=0 \
--duration=99999999 \
--cursor \
--x=$X \
--y=$Y \
--width=$WIDTH \
--height=$HEIGHT \
"${OUT_DIR}"/"${OUT_FN}"
}
if pidof byzanz-record >/dev/null
then
rec_stop
else
rec_start
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment