Command line

Use the droidline command from bash, zsh or PowerShell: how arguments work, what each command prints, exit codes, scripting patterns and scheduled jobs.

The droidline program that runs the server is also a command-line client. Every phone command works as a subcommand, so you can try things by hand, write shell scripts and run scheduled jobs without installing anything else.

droidline launch com.android.settings
droidline touch text "Network & internet"
droidline screenshot shot.png

The server must be running (droidline serve in another terminal) for every command except serve, version and help.

How a command line is built

droidline [global options] <command> [arguments] [--option value]

Arguments follow the order of the parameters in the command reference. Leave out optional ones from the end:

droidline touch text "Log in"            # by, value
droidline touch text "Log in" 0 30       # by, value, nth, timeout
droidline long_tap 540 1200 800          # x, y, ms

Options set any parameter by name, in any order. This is clearer for optional parameters:

droidline touch text "Log in" --timeout 30
droidline screenshot small.jpg --scale 0.5 --quality 70
droidline proxy @kr1 --app com.android.chrome

A few value types have their own spelling:

TypeWrite it asExample
Text with spacesIn quotesdroidline touch text "Close ad"
true / falsetrue or false (on/off also work)droidline wifi false
A yes/no optionThe option alone means truedroidline apps --system
A list of namesComma-separateddroidline notify_filter com.android.chrome,com.google.android.gm
Candidates for whichfield=value pairsdroidline which text="Log in" id=main_tab
Steps for batchJSON in single quotesdroidline batch '[["airplane",true],["sleep",3000],["airplane",false]]'

droidline help lists every command; droidline help touch shows one command's parameters, defaults and an example.

Global options

These go before the command:

OptionMeaning
--device NAME, -d NAMEThe phone to use. Needed when more than one is online.
--jsonPrint the server's raw reply as one JSON line.
--addr HOST:PORTServer address. Default 127.0.0.1:8780.
--token TOKENClient token, for a server on another machine.
--home DIRSettings folder, for serve and the setup commands.
droidline -d shelf-02 current
droidline --json exists text OK

The same settings can come from DROIDLINE_DEVICE, DROIDLINE_HOST, DROIDLINE_PORT and DROIDLINE_TOKEN.

What a command prints

The command returnsIt printsExample
one valuethe value alonedroidline exists text OK prints true
nothingokdroidline back
several fieldsone JSON linedroidline battery prints {"charging":true,"level":87,"temperature":31.5}
a dumpindented JSON, or the file name when you give onedroidline dump screen.json
a screenshotthe file name and sizeafter-login.png (1080x2400)

Errors go to standard error, so $(...) only captures real output.

Exit codes

CodeMeaning
0The command succeeded. A condition that answers false is still a success.
1The command failed: the element was not found, the phone is offline, the server rejected a parameter.
2The command line itself is wrong: an unknown command or option, or too many arguments.

Scripting in bash or zsh

Turn on set -e so the script stops at the first failure, read values with $(...), and compare conditions as text:

#!/usr/bin/env bash
set -e

droidline launch dev.droidline.demo

if [ "$(droidline exists text "Close ad")" = "true" ]; then
  droidline touch text "Close ad"
fi

balance=$(droidline get_text id balance)
echo "Balance is $balance"

# A failure you expect: handle it instead of stopping.
if ! droidline touch text "Maybe later" --timeout 3; then
  echo "no prompt this time"
fi

Loop over every online phone with jq:

for name in $(droidline --json devices | jq -r '.value[] | select(.online) | .name'); do
  droidline -d "$name" launch com.android.chrome &
done
wait   # the phones run in parallel; wait for all of them

PowerShell

The same script in PowerShell 7. Conditions come back as the strings true and false:

# Stop when a droidline command fails (PowerShell 7.4 and later).
$PSNativeCommandUseErrorActionPreference = $true
$ErrorActionPreference = "Stop"

droidline launch dev.droidline.demo

if ((droidline exists text "Close ad") -eq "true") {
  droidline touch text "Close ad"
}

$balance = droidline get_text id balance
"Balance is $balance"

# A failure you expect: check the exit code instead of stopping.
$PSNativeCommandUseErrorActionPreference = $false
droidline touch text "Maybe later" --timeout 3
if ($LASTEXITCODE -ne 0) { "no prompt this time" }

Loop over phones with PowerShell's own JSON support:

$phones = (droidline --json devices | ConvertFrom-Json).value | Where-Object online
foreach ($p in $phones) {
  droidline -d $p.name launch com.android.chrome
}

In Windows PowerShell 5.1, $PSNativeCommandUseErrorActionPreference does not exist; check $LASTEXITCODE after each command that must succeed.

Scheduled jobs

Because the CLI needs nothing but the server, it suits scheduled jobs. Make sure droidline serve runs all the time first (Configuration).

# crontab -e: every day at 07:00, wake the phone and open the morning app
0 7 * * * /home/me/.local/bin/droidline -d shelf-01 wake && /home/me/.local/bin/droidline -d shelf-01 launch com.example.news
$action  = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "-NoProfile -File C:\Scripts\morning.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 7am
Register-ScheduledTask -TaskName "Droidline morning" -Action $action -Trigger $trigger

Use full paths in scheduled jobs: they run with a smaller PATH than your terminal.

Setup commands

Besides phone commands, the CLI manages the server:

CommandWhat it does
droidline serveRun the server. Keep it open.
droidline pairShow a QR code for pairing a phone.
droidline pair <code> [--name NAME]Approve the phone that shows this 6-digit code.
droidline devicesList paired phones and their state.
droidline rename <id> <name>Give a phone a new name.
droidline revoke <device>Remove a phone's pairing.
droidline doctorCheck the setup and print the settings folder.
droidline token create|list|revokeClient tokens for using the server from another machine.
droidline relay set|status|offReach phones on mobile data through your relay.
droidline proxy add|list|removeSaved upstream proxies for the per-app proxy.
droidline webhook secretThe signing secret for notification webhooks.
droidline on_notification [--package P]Print each notification as a JSON line until you stop it.
droidline mcpRun the MCP server for AI agents.
droidline versionPrint the version.