Skip to content

Instantly share code, notes, and snippets.

@esutton
Last active March 2, 2021 20:50
Show Gist options
  • Save esutton/c71615324e26c2de448e009722dfd85c to your computer and use it in GitHub Desktop.
Save esutton/c71615324e26c2de448e009722dfd85c to your computer and use it in GitHub Desktop.
Capture screenshot from adb connected Android device & save to ~/Desktop
#!/bin/sh
############################################
# File: adb-cap.sh
# -----------------------
# Script to capture screenshot to file from adb connected Android device and save to ~/Desktop.
#
# 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 [ $# -eq 1 ]; then
fileName="$1"
fi
if ! [ ${fileName: -4} == ".png" ]; then
fileName=${fileName}.png
fi
fileNamePath=${fileSaveFolder}/${fileName}
echo "adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > ${fileNamePath}"
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > ${fileNamePath}
echo Saved to:
echo ${fileNamePath}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment