Skip to content

Instantly share code, notes, and snippets.

@LongboatAline
Last active April 11, 2018 12:31
Show Gist options
  • Save LongboatAline/56e06f30dcb515fdd11f4d38bae1574e to your computer and use it in GitHub Desktop.
Save LongboatAline/56e06f30dcb515fdd11f4d38bae1574e to your computer and use it in GitHub Desktop.
Shell script to take (and file) a screenshot from an Android device via adb
#!/bin/bash
# Installation: configure target directory, and make sure it exists
targetdir=/export/Android/Screenshots
prefix="android"
device=$(adb devices |awk 'NR == 2 {print $1}')
prefix=$device
#############################################
# Formatting: Field Separator, Date format
datefmt="+%Y-%m-%d_%H%M"
#############################################
yesterday=`TZ=CET+24 /bin/date '+%b %e'`
now=`/bin/date ${datefmt}`
utc=`TZ=UTC /bin/date ${datefmt}`
#############################################
targetfile=${prefix}-${now}
cd ${targetdir}
adb shell screencap -p /sdcard/${targetfile}.png && adb pull /sdcard/${targetfile}.png && adb shell rm /sdcard/${targetfile}.png
echo Screenshot saved to ${targetdir}/${targetfile}.png
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment