# Linking ADB commands

**URL:** https://discourse.mozilla.org/t/linking-adb-commands/31239
**Category:** Linux
**Created:** [August 26, 2018, 3:02pm UTC](https://discourse.mozilla.org/t/linking-adb-commands/31239 "2018-08-26T15:02:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![plwt](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/plwt/32/59480_2.png) [@plwt](https://discourse.mozilla.org/u/plwt)
#### Post date: [August 26, 2018, 3:02pm UTC](https://discourse.mozilla.org/t/linking-adb-commands/31239/1 "2018-08-26T15:02:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![leo](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/leo/32/35237_2.png) [@leo](https://discourse.mozilla.org/u/leo)
#### Post date: [August 29, 2018, 10:53am UTC](https://discourse.mozilla.org/t/linking-adb-commands/31239/2 "2018-08-29T10:53:39Z")

</div>

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

```auto
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:

```auto
#!/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:

```auto
./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:

```auto
NAME=`date -Iseconds`

```

---

<div class="post-metadata">

### Author: ![plwt](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/plwt/32/59480_2.png) [@plwt](https://discourse.mozilla.org/u/plwt)
#### Post date: [August 29, 2018, 8:22pm UTC](https://discourse.mozilla.org/t/linking-adb-commands/31239/3 "2018-08-29T20:22:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![rugkx](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/rugkx/32/19322_2.png) [@rugkx](https://discourse.mozilla.org/u/rugkx)
#### Post date: [September 2, 2018, 2:10pm UTC](https://discourse.mozilla.org/t/linking-adb-commands/31239/4 "2018-09-02T14:10:51Z")

</div>

> [@leo](#):
>
> Save that somewhere

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

---

<div class="post-metadata">

### Author: ![plwt](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/plwt/32/59480_2.png) [@plwt](https://discourse.mozilla.org/u/plwt)
#### Post date: [January 1, 2019, 1:25pm UTC](https://discourse.mozilla.org/t/linking-adb-commands/31239/5 "2019-01-01T13:25:21Z")

</div>

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:

> **[GitHub - plwt/AmazonMotionshot](https://github.com/plwt/AmazonMotionshot)**
>
> Contribute to plwt/AmazonMotionshot development by creating an account on GitHub.

and

> **[GitHub - plwt/AmazonScreenshot: Shell script using ADB to take a screenshot from...](https://github.com/plwt/AmazonScreenshot)**
>
> Shell script using ADB to take a screenshot from an Amazon Fire TV device.

I hope you find them useful.
