Created
June 27, 2019 16:55
-
-
Save d-j-kendall/9cebee5ec90ff3aafd5bf43f32bbb323 to your computer and use it in GitHub Desktop.
enhanced adb usage on MacOSX
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
#!/bin/bash | |
# Script adb+ | |
# Run any command adb provides on all your currently connected devices, | |
# Or prompt to select one device | |
# To use adb+ executable. | |
# Put the executable in this path | |
# '/usr/local/bin/' | |
# Then you can use adb+ commands like so: | |
# "adb+ --mirror" # prompts to to select a device and mirror or pipe it to mac using ffplay Must have ffmpeg and ffplay installed | |
# "adb+ --mirror -a" # same as before but opens a separate pipe for each connected device. | |
# "adb+ -a adb_command" # runs 'adb_command' on all devices. | |
# "adb+ -scap" # screen caps and pull the file to the current directory with a timestamp. | |
# Note: you must "mv adb+.sh adb+" then "sudo chmod+x adb+" | |
showHelp() { | |
echo "Usage: adb+ [-a] <command>" | |
echo " -h: show help" | |
echo " -scap: will caputre and pull screenshot to current directory, -scap -a will pull all screenshots to current directory" | |
echo " --mirror: mirror device screen using ffplay" | |
echo " -a: run command on all device" | |
echo " command: normal adb commands" | |
echo | |
echo "Examples:" | |
echo " adb+ -a install apidemo.apk" | |
echo " adb+ shell" | |
echo " adb+ --mirror" | |
echo " Note: '-a' option must come before commands and after adb+ native options" | |
} | |
TIMESTAMP=$(date +"%Y%m%d-%H%M%S") | |
if [[ $1 = '-h' ]]; then | |
showHelp | |
exit | |
fi | |
DEVICES=() | |
while read line | |
do | |
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ] | |
then | |
device=`echo $line | awk '{print $1 " - " $5} '` | |
DEVICES+=("${device}") | |
fi | |
done < <(adb devices -l) | |
#echo "${DEVICES[@]}" | |
if [[ $1 = '-scap' ]]; then | |
if [[ ${#DEVICES[@]} -lt 2 ]]; then | |
device=`echo $device | awk '{print $1}'` | |
adb shell screencap -p /sdcard/screenshot$device-$TIMESTAMP.png && adb pull /sdcard/screenshot$device-$TIMESTAMP.png | |
exit | |
fi | |
if [[ $2 = '-a' ]]; then | |
shift | |
export DEVICES | |
for dev in "${DEVICES[@]}" | |
do | |
device=`echo $dev | awk '{print $1}'` | |
export device | |
adb -s $device shell screencap -p /sdcard/screenshot$device-$TIMESTAMP.png && adb -s $device pull /sdcard/screenshot$device-$TIMESTAMP.png | |
done | |
exit | |
fi | |
# select | |
PS3="Enter number to select: " | |
DEVICES+=('all') | |
select dev in "${DEVICES[@]}" | |
do | |
case "$dev" in | |
'all') | |
$0 -scap -a $* | |
break;; | |
*) | |
device=`echo $dev | awk '{print $1}'` | |
adb -s $device shell screencap -p /sdcard/screenshot$device-$TIMESTAMP.png && adb -s $device pull /sdcard/screenshot$device-$TIMESTAMP.png | |
break;; | |
esac | |
done | |
exit | |
fi | |
if [[ $1 = '--mirror' ]]; then | |
if [[ ${#DEVICES[@]} -lt 2 ]]; then | |
device=`echo $device | awk '{print $1}'` | |
nohup adb shell "while true; do screenrecord --bit-rate=64M --output-format=h264 --size 1280x800 --time-limit 5 -; done" | ffplay -framerate 32 -framedrop -bufsize 512M - > /dev/null 2>&1 & disown | |
exit | |
fi | |
if [[ $2 = '-a' ]]; then | |
shift | |
export DEVICES | |
for dev in "${DEVICES[@]}" | |
do | |
device=`echo $dev | awk '{print $1}'` | |
export device | |
nohup adb -s $device shell "while true; do screenrecord --bit-rate=64M --output-format=h264 --size 1280x800 --time-limit 5 -; done" | ffplay -framerate 32 -framedrop -bufsize 512M - > /dev/null 2>&1 & disown | |
done | |
exit | |
fi | |
# select | |
PS3="Enter number to select: " | |
DEVICES+=('all') | |
select dev in "${DEVICES[@]}" | |
do | |
case "$dev" in | |
'all') | |
$0 --mirror -a $* | |
break;; | |
*) | |
device=`echo $dev | awk '{print $1}'` | |
adb -s $device shell "while true; do screenrecord --bit-rate=64M --output-format=h264 --size 1280x800 --time-limit 5 -; done" | ffplay -framerate 32 -framedrop -bufsize 512M - | |
break;; | |
esac | |
done | |
exit | |
fi | |
if [[ ${#DEVICES[@]} -lt 2 ]]; then | |
adb $@ | |
exit | |
fi | |
if [[ $1 = '-a' ]]; then | |
shift | |
export DEVICES | |
for dev in "${DEVICES[@]}" | |
do | |
export device=`echo $dev | awk '{print $1}'` | |
device=`echo $dev | awk '{print $1}'` | |
adb -s $device $@ | |
done | |
exit | |
fi | |
# select | |
PS3="Enter number to select: " | |
DEVICES+=('all') | |
select dev in "${DEVICES[@]}" | |
do | |
case "$dev" in | |
'all') | |
$0 -a $* | |
break;; | |
*) | |
adb -s `echo $dev | awk '{print $1}'` $@ | |
break;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment