Skip to content

Instantly share code, notes, and snippets.

@annie-l
Last active September 11, 2017 17:23
Show Gist options
  • Save annie-l/faa2fb46a2ad4bd61a09a9d021b7492e to your computer and use it in GitHub Desktop.
Save annie-l/faa2fb46a2ad4bd61a09a9d021b7492e to your computer and use it in GitHub Desktop.
screenshot command: captures screenshot from current device via adb and saves it to your desktop. input an optional filename. save this to /usr/local/bin to use anywhere.
#!/bin/bash
# What: Pull screenshot from connected device and save it to the Desktop (on Mac)
# Usage: screenshot
# Examples:
#> screenshot foo
# (creates [device name]-foo.png on the Desktop)
#> screenshot
# (creates [device name]-[date_time].png on the Desktop)
# Notes: update FILEPATH to change directory. if you set it to empty ("FILEPATH=") it will save to the current directory.
# Update IGNORE_EMULATORS to ignore any connected emulators.
FILEPATH=~/Desktop/
FILENAME=("-`date +%Y-%m-%d_%H.%M.%S`.png")
IGNORE_EMULATORS=false
if [ $1 ]; then
FILENAME="-$1.png"
fi
for line in `adb devices | grep -v "List" | awk '{print $1}'`
do
DEVICE=`echo $line | awk '{print $1}'`
if [[ $IGNORE_EMULATORS == false || ($IGNORE_EMULATORS == true && $DEVICE != emulator*) ]]
then
if [ -z "$FILEPATH" ]
then
echo "saving $DEVICE$FILENAME to current directory"
else
echo "saving $DEVICE$FILENAME to $FILEPATH"
fi
adb -s $DEVICE shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > $FILEPATH$DEVICE$FILENAME
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment