Last active
June 30, 2021 12:05
-
-
Save danybony/d8bdb15445b4c3965f6196c6213fc545 to your computer and use it in GitHub Desktop.
Android screenshot to current dir
This file contains hidden or 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 | |
while getopts y: flag | |
do | |
case "${flag}" in | |
y) size=${OPTARG};; | |
esac | |
done | |
DEVICES=`adb devices | grep -v devices | grep device | cut -f 1` | |
for device in $DEVICES; do | |
output="screen_$(echo $device)_$(date +%Y%m%d_%H%M%S).png" | |
echo "Capturing from $device" | |
adb -s $device shell screencap -p /sdcard/screen.png | |
adb -s $device pull /sdcard/screen.png $output | |
adb -s $device shell rm /sdcard/screen.png | |
if [ ! -z $size ] | |
then | |
sips -Z $size $output | |
fi | |
done |
do you use this in some UI test? Or what is the use case. Thanks.
Thanks for the script!
I've modified it a bit to suit my need (working with devices with multiple screens like the Samsung Z Fold):
#!/bin/bash
while getopts y: flag
do
case "${flag}" in
y) size=${OPTARG};;
esac
done
DEVICES=`adb devices | grep -v devices | grep device | cut -f 1`
for device in $DEVICES; do
DISPLAYS=`adb -s $device shell dumpsys SurfaceFlinger --display-id | cut -d" " -f 2`
for display in $DISPLAYS; do
echo "Capturing from $display on $device"
output="screen_$(echo $device)_$(echo $display)_$(date +%Y%m%d_%H%M%S).png"
adb -s $device exec-out screencap -p -d $display > $output
if [ ! -z $size ]; then
sips -Z $size $output
fi
done
done
BTW: Using exec-out
you can avoid to generate the file on the device and then copy/delete it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A small batch script that captures screenshots from all the connected Android devices and stores them in the current directory.
Optional parameter
-y
to specify the longest size to resize the grabbed screenshot. If not specified the original size will be kept.