Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Command line android screenshots via ADB
#!/bin/bash
# droidshot: droidshot [filename] - Saves screenshots via ADB to filename
function droidshot() {
local formatter="%03d"
local file="$1"
local n=1
local fn=$(printf "${formatter}" $n)
if [[ "$file" == "" ]]; then
file="droidshot-"$(date "+%d-%m-%Y-")
files=`ls ${file}* 2>/dev/null|awk '{print $1}'`
ext=".png"
for i in $files; do
echo $i
echo "${file}${fn}${ext}"
if [[ "${file}${fn}${ext}" == "${i}" ]]; then
n=$(( n + 1 ))
echo $n
fi
fn=$(printf "${formatter}" $n)
done
file="${file}${fn}${ext}"
fi
echo "Screenshotting to ${file}.."
adb shell screencap -p 2> /dev/null | perl -pe 's/\x0D\x0A/\x0A/g' > $file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment