Skip to content

Instantly share code, notes, and snippets.

@jokester
Created May 22, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokester/77b6cb63b1fff8fdf6d00af7a225f0c7 to your computer and use it in GitHub Desktop.
Save jokester/77b6cb63b1fff8fdf6d00af7a225f0c7 to your computer and use it in GitHub Desktop.
capture screenshot with adb && pull from pc
#!/usr/bin/env bash
set -ue
set -o pipefail
temp_basename="screenshot-$(date '+%Y%m%d-%H%M%S-%N').png"
temp_remote="/sdcard/$temp_basename"
temp_local="/tmp/$temp_basename"
(
adb shell screencap -p "$temp_remote"
adb pull "$temp_remote" "$temp_local"
adb shell rm "$temp_remote"
echo "screenshot saved at $temp_local"
) >&2
if [[ ! -t 1 ]]; then
exec cat "$temp_local"
else
echo "FYI: this script can be used to pipe the new screenshot into a file"
echo " e.g. $0 > screen.png"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment