Last active
May 23, 2017 14:41
-
-
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.
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 | |
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 |
find: Screenshot-20160323-125825*.png': No such file or directory convert.im6: unable to open image
Screenshot-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
The script runs on your computer, not your device.
Simply put it in a folder on your machine,
chmod +x android-screen-gif.sh
and./android-screen-gif.sh
You'll also need to install the ImageMagick to your path (
convert
).However, it looks like you're using a Windows machine which means you're out of luck for running shell scripts, sorry about that (buy a Mac :) ).