Skip to content

Instantly share code, notes, and snippets.

@davidofwatkins
Last active October 18, 2018 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidofwatkins/467c8089f7880f3e6fe1dc76b0952628 to your computer and use it in GitHub Desktop.
Save davidofwatkins/467c8089f7880f3e6fe1dc76b0952628 to your computer and use it in GitHub Desktop.
A utility to record your Android screen via ADB
if [[ ! $(which adb) ]]; then
echo "adb not found."
exit 1
fi
if [[ ! $(adb devices | grep "\tdevice") ]]; then
echo "No devices found."
exit 1
fi
name="screen-recording-$(date '+%Y-%m-%d-%H:%M:%S').mp4"
path="/sdcard/screen-recordings/$name"
# turn on 'show touches' debug setting
adb shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:1
printf "\nScreen recording. Press ctrl+c to stop.\n\n"
adb shell mkdir -p /sdcard/screen-recordings/
adb shell screenrecord $path
# turn 'show touches' off
adb shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:0
# pull the video off the device
adb pull $path . >/dev/null
adb shell rm $path
echo "Screen recording created at: $name"
if [[ ! $(which adb) ]]; then
echo "adb not found."
exit 1
fi
if [[ ! $(adb devices | grep "\tdevice") ]]; then
echo "No devices found."
exit 1
fi
name="screenshot-$(date '+%Y-%m-%d-%H:%M:%S').png"
path="/sdcard/screenshots/$name"
adb shell mkdir -p /sdcard/screenshots/
adb shell screencap -p $path
adb pull $path . >/dev/null
adb shell rm $path
echo "Screenshot created at: $name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment