Skip to content

Instantly share code, notes, and snippets.

@sveinungkb
Last active May 23, 2017 14:41
Show Gist options
  • Save sveinungkb/3a5753da908489fc0c26 to your computer and use it in GitHub Desktop.
Save sveinungkb/3a5753da908489fc0c26 to your computer and use it in GitHub Desktop.
Bash script to record screenshots on Android until interrupted, then assemble all screenshots to an animated GIF. Useful for demos etc. Requires ImageMagick's (convert) to be on your path.
#!/bin/sh
PREFIX="Screenshot-$(date +%Y%m%d-%H%M%S)"
BASE="/sdcard/$PREFIX"
DELAY=300
trap ctrl_c INT
function clean_up() {
rm -f $PREFIX*.png
echo "Cleaned up individual screenshots."
adb $1 $2 shell rm -rf $BASE
}
function pull_images() {
echo "Downloading images."
adb $1 $2 pull "$BASE/"
}
function assemble_gif() {
for image in $PREFIX/*.png; do
if [[ $(identify -quiet $image) ]]; then
echo "Valid image $image"
else
echo "Invalid image file $image, deleting"
rm -f $image
fi
done
convert -delay $DELAY -loop 0 "$PREFIX/*.png" $PREFIX.gif
echo "Assembled gif $PREFIX.gif"
}
running=1
function ctrl_c() {
echo "Will clean up"
running=-1
}
adb shell mkdir $BASE
i=0
while [ $running -ge 0 ]
do
i=$(($i+1))
IMAGE="$BASE/$PREFIX-$i.png"
adb $1 $2 shell screencap -p $IMAGE
echo "Wrote screenshot to $IMAGE"
done
pull_images
assemble_gif
clean_up
open $PREFIX.gif
@samoylenkodmitry
Copy link

find: Screenshot-20160323-125825*.png': No such file or directory convert.im6: unable to open imageScreenshot-20160323-125825_.png': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: unable to open file Screenshot-20160323-125825_.png' @ error/png.c/ReadPNGImage/3667. convert.im6: no images defined Screenshot-20160323-125825.gif' @ error/convert.c/ConvertImageCommand/3044.
Assembled gif Screenshot-20160323-125825.gif
Cleaned up individual screenshots.
Couldn't get a file descriptor referring to the console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment