Created
August 21, 2018 22:39
-
-
Save FriendlyTester/20c06afdde794470884ff90166258b7c to your computer and use it in GitHub Desktop.
Record Android with ADB and Download the File
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 record 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 recordScreen(){ | |
echo "Recording '${FILENAME}'..." | |
adb shell screenrecord --bit-rate 6000000 /sdcard/${FILENAME} & | |
_PID=$! | |
read -r -p "Press [Enter] to stop recording..." | |
kill ${_PID} | |
echo "Stopping recording..." | |
while kill -0 "${_PID}"; do | |
sleep 0.5 | |
done | |
echo "Downloading recording..." | |
adb pull /sdcard/${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} =~ ^.*mp4$ ]]; then | |
FILENAME="${_ARGUMENT}.mp4" | |
else | |
FILENAME="${_ARGUMENT}" | |
fi | |
;; | |
esac | |
done | |
checkIfFileExists | |
recordScreen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment