Shell Script to Take a Screenshot of Android Devices

Here is a Shell Script to take a screenshot of Android devices. You need setup adb before running this script. The script temporary saves the screenshot to device’s local /sdcard/, then move the file to current directory. The format of image is PNG, and the file name is {timestamp}.png.

filename=`date "+%s"`
adb shell screencap -p /sdcard/${filename}.png
adb pull /sdcard/${filename}.png
adb shell rm /sdcard/${filename}.png

The adb option of -p at the second line is for taking a screen shot with PNG format, but the document does not put the option, so maybe it is not required :)

Save the script asscreenshot.sh and run.

% sh screenshot.sh

Environment

  • macOS Big Sur 11.4
  • zsh 5.8

References

  1. Android Debug Bridge (adb)  |  Android Developers (Last access: 2021/06/15)

About me

Experienced software developer. Technical lead at Fuller, Inc. My speciality is developing Android native app. I'm living in Tsukuba Japan, with my family, dogs, and cats :)

Here is more detailed profile.