Skip to content

Instantly share code, notes, and snippets.

@avbk
Last active February 15, 2019 09:11
Show Gist options
  • Save avbk/a10c96f3558191fc1d4b to your computer and use it in GitHub Desktop.
Save avbk/a10c96f3558191fc1d4b to your computer and use it in GitHub Desktop.
Take a scaled screenshot via adb

Dependencies

  • Android SDK in $PATH
  • ImageMagick (Ubuntu: sudo apt-get install imagemagick)

Usage

$ bash adbscreen.sh a_filename

Takes a screenshot (e.g. a_filename.png) from the connected android device (or emulator, depending on what adb selects) and puts it into the working directory. The script will repaint the left part of the notification bar so that any pending notifications will be hidden.

$ bash adbscreen.sh a_filename 25

Takes a screenshot (e.g. a_filename.png) from the connected android device (or emulator, depending on what adb selects) and puts it into the working directory. The script will repaint the left part of the notification bar so that any pending notifications will be hidden. Finally the screenshot will be scaled depending on the scale parameter (e.g. down to 25% of its original size)

#/bin/bash
filename=$1
if test $# -gt 1; then
scale=$2
echo "Capturing $filename.png at a scale of $scale%"
else
echo "Capturing $filename.png"
fi
tmpfile="/sdcard/$filename.png"
adb shell screencap -p $tmpfile
adb pull $tmpfile
adb shell rm $tmpfile
convert "$filename.png" -fill black -draw "rectangle 0,0 400,48" "$filename.png"
if test $# -gt 1; then
mogrify -resize $scale% "$filename.png"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment