Skip to content

Instantly share code, notes, and snippets.

@leighmcculloch
Created December 5, 2013 10:22
Show Gist options
  • Save leighmcculloch/7803130 to your computer and use it in GitHub Desktop.
Save leighmcculloch/7803130 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
@Tofdu31
Copy link

Tofdu31 commented Nov 27, 2018

Hi,

I have an error :

Taking Screenshot at 112018- 94713,68
Output File: screenshot-112018- 94713,68.png

usage: screencap [-hp] [-d display-id] [FILENAME]
   -h: this message
   -p: save the file as a png.
   -d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.
remote object '/sdcard/screenshot-112018-' does not exist
rm: /sdcard/screenshot-112018-: No such file or directory
rm: 94713,68.png: No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment