Skip to content

Instantly share code, notes, and snippets.

@esutton
Created February 15, 2019 20:44
Show Gist options
  • Save esutton/922625ac152e61b8b79b29088e20ea92 to your computer and use it in GitHub Desktop.
Save esutton/922625ac152e61b8b79b29088e20ea92 to your computer and use it in GitHub Desktop.
Script uses android adb to grab screen capture to PNG
#!/bin/sh
############################################
# File: adb-cap.sh
# -----------------------
# Script to capture screenshot to file from adb connected Android device and saves to ~/Desktop.
#
# If no file name arg is found, a unique file name is created from current date.
#
# Ed Sutton
# Free for any use.
# Tested on macOS
# Debug on: set -x
#set -x
fileSaveFolder=~/Desktop
fileName=adb-cap-`date +%Y-%m-%d_%H-%M-%S`.png
# If user provided file name argument, then use it
if [ $# -eq 1 ]; then
fileName="$1"
fi
# Add a png extension if user forgot
if ! [ `echo ${fileName: -4} | tr [:upper:] [:lower:]` == ".png" ]; then
fileName=${fileName}.png
fi
fileNamePath=${fileSaveFolder}/${fileName}
adb exec-out screencap -p > ${fileNamePath}
echo Saved to:
echo ${fileNamePath}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment