Skip to content

Instantly share code, notes, and snippets.

@tsohr
Last active July 7, 2017 07:03
Show Gist options
  • Save tsohr/7820699 to your computer and use it in GitHub Desktop.
Save tsohr/7820699 to your computer and use it in GitHub Desktop.
Timestamp appended screen capture with ADB (android debug bridge) in Windows environment
#!/bin/bash
adb='/cygdrive/c/Android/sdk/platform-tools/adb.exe'
$adb shell screencap -p | perl -pe 's/\x0D\x0D\x0A/\x0A/g' > screen.png
STAMP=`date +"%Y%m%d_%H%M%S"`
mv -f screen.png screen-$STAMP.png
[Administrator@tsohr-PC screen]$ xxd wrong.png | head
00000000: 8950 4e47 0d0d 0d0a 1a0d 0d0a 0000 000d .PNG............
00000010: 4948 4452 0000 05a0 0000 0d0d 0a00 0806 IHDR............
00000020: 0000 0047 f485 cf00 0000 0473 4249 5408 ...G.......sBIT.
00000030: 0808 087c 0864 8800 0020 0049 4441 5478 ...|.d... .IDATx
00000040: 01ec d8b1 0dc0 300c 0431 c5fb ef9c a4f0 ......0..1......
00000050: 08ba 8e06 dc7e 41a8 ba67 66de ff7b 0408 .....~A..gf..{..
00000060: 1020 4080 0001 0204 0810 2040 8000 0102 . @....... @....
00000070: 0408 1020 4060 55e0 acae 1923 4080 0001 ... @`U....#@...
00000080: 0204 0810 2040 8000 0102 0408 1020 4080 .... @....... @.
00000090: 0001 0257 4080 760d 0d0a 0408 1020 4080 ...W@.v...... @.
[Administrator@tsohr-PC screen]$ xxd device-2017-07-07-155833.png | head
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
00000010: 0000 05a0 0000 0a00 0806 0000 0047 f485 .............G..
00000020: cf00 0080 0049 4441 5478 daec dd07 dc14 .....IDATx......
00000030: e5bd fffd e373 cef9 9fff 93f3 fccb 69f1 .....s........i.
00000040: e4c4 24e6 184d 8cd1 2426 5163 8e8a 0d2b ..$..M..$&Qc...+
00000050: 16ec 8802 8ad2 4111 0451 aa74 912e bd83 ......A..Q.t....
00000060: f4de 912a 20bd 5791 2645 4090 5ea4 88d7 ...* .W.&E@.^...
00000070: e377 7216 f7de 7b76 f79a d9d9 dd99 fbfe .wr...{v........
00000080: 5caf d7fb 15c3 bd3b 333b 3b3b bbf3 9deb \......;3;;;....
00000090: fa5d 7f73 d955 250d 0000 0000 0000 0000 .].s.U%.........
@echo off
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%-%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,2%
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
move /y screen.png screen-%ldt%.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment