Skip to content

Instantly share code, notes, and snippets.

@romainbriche
Forked from leighmcculloch/Android Screenshot.bat
Created December 18, 2017 10:29
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 romainbriche/bcd39047b2118744d157994409847b7d to your computer and use it in GitHub Desktop.
Save romainbriche/bcd39047b2118744d157994409847b7d to your computer and use it in GitHub Desktop.
This batch script will take a screenshot on an Android device using ADB, download the screenshot to the directory this script to the current directory and then remove the screenshot file from the device. Screenshots are saved with filename: screenshot-YYYYMMDD-HHMMSS.png. ADB must be connected to a device already.
@echo off
rem configurable parameters
set SCREENCAP_FILE_PREFIX=screenshot
rem the dir on the device where the screenshot will be stored temporarily
set SCREENCAP_WORKING_DIR=/sdcard/
rem adb path, leave blank if adb is already on the user or system path
set SCREENCAP_ADB_PATH=
rem get date and time
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set SCREENCAP_DATE=%%c%%a%%b)
For /f "tokens=1-4 delims=/:." %%a in ("%TIME%") do (set SCREENCAP_TIME=%%a%%b%%c%%d)
rem create output file from parameters and date and time
set SCREENCAP_FILE_NAME=%SCREENCAP_FILE_PREFIX%-%SCREENCAP_DATE%-%SCREENCAP_TIME%.png
set SCREENCAP_FILE_PATH=%SCREENCAP_WORKING_DIR%%SCREENCAP_FILE_NAME%
rem do it!
echo Taking Screenshot at %SCREENCAP_DATE%-%SCREENCAP_TIME%
echo Output File: %SCREENCAP_FILE_NAME%
echo.
%SCREENCAP_ADB_PATH%adb shell screencap -p %SCREENCAP_FILE_PATH%
%SCREENCAP_ADB_PATH%adb pull %SCREENCAP_FILE_PATH%
%SCREENCAP_ADB_PATH%adb shell rm %SCREENCAP_FILE_PATH%
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment