Linking ADB commands

Hi

As part of my work as a contributor supporting our awesome Android products, I sometimes use the Android Debug Bridge (ADB) to take screenshots. To do this I have to type (in terminal, after connecting):

  • adb shell screencap -p /sdcard/filename.png (to take the screenshot)
  • adb pull /sdcard/filename.png /tmp (to move the screenshot from the Android device to my laptop)
  • adb shell rm /sdcard/filename.png (to delete the screenshot from the Android device)

It is really cool but is a bit fiddly to keep typing in, especially if you are taking a number of screenshots. Does anyone know how I could link these commands together and what the result could look like?

Welcome peoples thoughts, thank you for your input.

Can you use the && operator to turn it into a one-liner?

adb shell screencap -p /sdcard/filename.png && adb pull /sdcard/filename.png /tmp && adb shell rm /sdcard/filename.png

Or is the issue there you need to specify a unique screenshot name? Then a script might do the job for you:

#!/bin/bash

NAME=$1

adb shell screencap -p /sdcard/$NAME.png
adb pull /sdcard/$NAME.png /tmp
adb shell rm /sdcard/$NAME.png

Save that somewhere and then run chmod +x script-name.sh to make it executable:

./script-name.sh screenshot-name

Would save it as screenshot-name.png

Or you could even get the script to name the screenshot with a date and time by replacing NAME=$1 above with something like:

NAME=`date -Iseconds`
1 Like

Thanks @leo , the && approach is exactly what I was looking for! Awesome!

I will be doing further work with this to embed it in something, but hope to be able to share the results here very soon so that others can use it.

1 Like

BTW, usually something like /usr/local/bin is recommend and would be an appropriate place.

1 Like

Hi

I appreciate (and am sorry) that it has been a while, but this is what I have built using the help above to link some commands for Android Debug Bridge together:

and

I hope you find them useful.