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
@abhilash1in
Copy link

error

I tried to run it by saying "./android-screen-gif.sh" and"sh android-screen-gif.sh"
It gives me an error saying "Permission denied" in the first case and "device not found" in the second
I also changed the permissions and tried to run it, no difference.
I tried placing the script file in both sdcard and external_sd directories and running it. No difference.
I copy pasted the script file into my phone. Should I modify it in any way to match my phone?
My phone is Samsung Galaxy S4, GT i9500. I'm using GearCM12.1 rom, debugging is enabled, phone is rooted.
How do I run this script? Please help

@sveinungkb
Copy link
Author

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 :) ).

@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