Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/system/bin/sh
- # wearcap v1 - screencaps a Wear device from the phone
- # created by CEnnis91
- VERSION=1
- ADBKEY="/data/misc/adb/adb_keys"
- OUTDIR="/sdcard/Pictures/Screenshots"
- TSTAMP="+Screenshot_%Y-%m-%d-%H-%M-%S.png"
- TMPDIR="/data/local/tmp"
- clear
- setprop service.adb.tcp.port 5555
- mkdir -p $OUTDIR $TMPDIR
- echo "wearcap v$VERSION (screencap your Wear device) - created by CEnnis91"
- echo ""
- if [ "$(whoami)" != "root" ]; then
- echo "- You must be root to run wearcap."
- exit 2
- fi
- # take screenshots interactively
- wearcap() {
- echo ""
- echo "- Connection to your Wear device is complete!"
- echo "- To screenshot press [SPACE], to exit press [X]."
- echo "- Screenshots can be found in $OUTDIR."
- echo ""
- while [ "$INPUT" != "x" ]; do
- stty -echo
- read -N 1 INPUT
- stty echo
- # this will take a few seconds to take and send over
- if [ "$INPUT" == "" ]; then
- OUTPUT=$(date "$TSTAMP")
- adb -s localhost:4444 shell screencap -p $TMPDIR/$OUTPUT > /dev/null 2>&1
- adb -s localhost:4444 pull $TMPDIR/$OUTPUT $OUTDIR/$OUTPUT > /dev/null 2>&1
- adb -s localhost:4444 shell rm -f $TMPDIR/$OUTPUT > /dev/null 2>&1
- if [ -e $OUTDIR/$OUTPUT ]; then
- echo "- Screenshot taken: $OUTPUT."
- else
- echo "- It appears the screenshot was not created."
- echo "- Run $0 again to try to reconnect properly."
- exit 1
- fi
- fi
- done
- }
- if [ -e $TMPDIR/.android ]; then
- localkey="$(cat $TMPDIR/.android/adbkey.pub)"
- validkey=$(grep -s "$localkey" $ADBKEY)
- fi
- if [ -n "$validkey" ]; then
- echo "Preparing for screenshot..."
- echo "- Make sure the screen is on during connection."
- echo "- This will take a few seconds to connect."
- echo "- Make sure the screen of your watch is on."
- adb kill-server > /dev/null 2>&1
- HOME=$TMPDIR adb start-server > /dev/null 2>&1
- adb connect localhost > /dev/null 2>&1
- sleep 2
- adb forward tcp:4444 localabstract:/adb-hub > /dev/null 2>&1
- adb connect localhost:4444 > /dev/null 2>&1
- sleep 2
- wearcap
- exit 0
- fi
- # we need to give the user more time to authorize the RSA keys here
- echo "Initializing the environment first..."
- echo "- You will be asked to authorize two devices for ADB access."
- echo "- The first is this device, the second is your Wear device."
- echo "- Make sure the screen of your watch is on during this process."
- echo ""
- adb kill-server
- HOME=$TMPDIR adb start-server
- # authorize and connect to the phone
- adb connect localhost
- sleep 7
- # authorize and connect to the watch
- adb forward tcp:4444 localabstract:/adb-hub
- adb connect localhost:4444
- sleep 7
- devices=$(adb devices | grep "localhost.*device" | wc -l)
- if [ $devices -eq 2 ]; then
- echo "- Success!"
- wearcap
- exit 0
- else
- echo "- Failure!"
- echo "- Run $0 again to try to reinitialize."
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement