Skip to content

Instantly share code, notes, and snippets.

Created Jan 4, 2019
What would you like to do?
ADB that prompts for which device when multiple devices are available
#!/usr/bin/env python
import sys
import subprocess
def get_devices():
pipe = subprocess.PIPE
process = subprocess.Popen(["adb", "devices"], stdin=pipe, stdout=pipe, stderr=pipe)
output, error = process.communicate()
output_lines = output.strip().split("\n")
list_of_devices = []
for line in output_lines[1:]:
return list_of_devices
def prompt_for_device(devices):
for index,device in enumerate(devices):
print("[{0}]: {1}".format(index, device))
result = raw_input("Which device? [0]: ") or "0"
return int(result)
def adb(args, device = None):
if device:["adb", "-s", device] + args)
else:["adb"] + args)
adb_args = sys.argv[1:]
devices = get_devices()
if len(devices) > 1:
device_index = prompt_for_device(devices)
device = devices[device_index]
adb(adb_args, device)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment