Skip to content

Instantly share code, notes, and snippets.

@oskuhsiu
Forked from sveinungkb/android-screen-gif.sh
Created October 14, 2015 14:17
Show Gist options
  • Select an option

  • Save oskuhsiu/84bcd12ebc3d75a5f8fe to your computer and use it in GitHub Desktop.

Select an option

Save oskuhsiu/84bcd12ebc3d75a5f8fe 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.
#!/bin/sh
echo "Press Ctrl + C to stop recording"
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."
}
function pull_images() {
echo "Downloading images."
adb $1 $2 pull "$BASE/"
find $PREFIX*.png -empty -delete
}
function assemble_gif() {
convert -delay $DELAY -loop 0 $PREFIX*.png $PREFIX.gif
echo "Assembled gif $PREFIX.gif"
}
running=1
function ctrl_c() {
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment