Skip to content

Instantly share code, notes, and snippets.

@amahdy
Last active July 16, 2023 18:07
Show Gist options
  • Save amahdy/58ec7241eda0e8fcb963821b34104250 to your computer and use it in GitHub Desktop.
Save amahdy/58ec7241eda0e8fcb963821b34104250 to your computer and use it in GitHub Desktop.
Automatic screen capture for Android
# I needed to automatically caputre screen of a book on an Android device
# The process is to: `screenshot` then `swipe left` for some 1000+ times
# This code can help performing those operations:
# Assuming you have installed and configured `adb`,
# and you are authenticated to execute `adb` commands on the device from a bash script:
# Folder in the device to save screenshots
SAVEDIR="/storage/emulated/0/Download/Book7"
# Specify number of pages
PAGES=7500
for (( c=1; c<=$PAGES; c++ ))
do
# Each screenshot will get an auoatic name + timestamp to easily sort
# e.g. P1689514276.png, P1689514278.png, P1689514279.png ..etc
adb shell screencap -p $SAVEDIR/M$(date +%s).png
# Swipe left from the middle of the screen approximately
adb shell input touchscreen swipe 700 700 500 700 100
# Comment previous line and use this instead for RTL
# adb shell input touchscreen swipe 200 700 500 700 100
# Wait 1 second for any possible screen swipe animation
sleep 1
done
# Alert when done
echo -ne '\007'
# Optional: pull screenshots into the host device
# Notice the same path as above
adb pull $SAVEDIR/.
# Alert again when transfer is done
echo -ne '\007'
# Due to `sleep` I estimate that this operation takes ~1.5 second per page.
# For 7500 pages, it takes ~ 3 hours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment