Skip to content

Instantly share code, notes, and snippets.

@ZevEisenberg
Created March 27, 2014 14:39
Show Gist options
  • Save ZevEisenberg/9808986 to your computer and use it in GitHub Desktop.
Save ZevEisenberg/9808986 to your computer and use it in GitHub Desktop.
Function to take a screenshot on the currently-connected Android device and drop it on your Mac’s Desktop.
function androidScreenshot
{
# only do this if there is a device connected
adb shell exit 2>/dev/null
if [[ $? == 0 ]]; then
# Example filename: ~/Desktop/Android Screen 2013-09-11 12.32.16 PM.png
# perl line ending hacks from http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
dateString=`date +"%Y-%m-%d at %I.%M.%S %p"`
fileName="Android Screen $dateString.png"
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > ~/Desktop/$fileName
else
echo "No android device connected."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment