Created
August 21, 2018 22:34
-
-
Save FriendlyTester/5327133f263fc51124725002be1577fb to your computer and use it in GitHub Desktop.
ADB Take Screenshot and Pull It
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
function usage(){ | |
echo -e "\nThis script will screenshot what is happening on an Android device" | |
echo -e " " | |
echo -e "Usage: './`basename $0` foo' or './`basename $0` foo.mp4'" | |
echo -e "Both of the above will produce a recording with the filename 'foo.mp4'" | |
echo -e "\n*** Optional Parameters ***\n" | |
echo -e "-h | --help \t\t\t Show this help!" | |
echo -e " " | |
exit 1 | |
} | |
function checkIfFileExists(){ | |
if [ -f ${FILENAME} ]; then | |
echo "[ERROR] The recording you are trying to create already exists!" | |
read -r -p "Do you want to overwrite this file? [y/N] " RESPONSE | |
RESPONSE=`echo ${RESPONSE}| awk '{print tolower($0)}'` | |
if [[ (${RESPONSE} == "" || ${RESPONSE} == "n" || ${RESPONSE} == "no") ]];then | |
exit 1 | |
fi | |
fi | |
} | |
function takeScreenshot(){ | |
echo "Taking screenshot '${FILENAME}'..." | |
adb shell screencap -p /sdcard/${FILENAME} | |
echo "Process complete." | |
} | |
function pullScreenshot(){ | |
echo "Downloading screenshot '${FILENAME}'..." | |
adb pull /sdcard/${FILENAME} | |
echo "Process complete." | |
} | |
function deleteScreenshotFromDevice(){ | |
echo "Deleting screenshot '${FILENAME}'..." | |
adb shell rm /sdcard/${FILENAME} | |
echo "Process complete." | |
exit 0 | |
} | |
[[ $# -eq 1 ]] || { usage; } | |
for _ARGUMENT in "$@" | |
do | |
case ${_ARGUMENT} in | |
-h|--help) | |
usage | |
;; | |
*) | |
if [[ ! ${_ARGUMENT} =~ ^.*png$ ]]; then | |
FILENAME="${_ARGUMENT}.png" | |
else | |
FILENAME="${_ARGUMENT}" | |
fi | |
;; | |
esac | |
done | |
checkIfFileExists | |
takeScreenshot | |
pullScreenshot | |
deleteScreenshotFromDevice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment