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:
| Type | Write it as | Example |
|---|---|---|
| Text with spaces | In quotes | droidline touch text "Close ad" |
| true / false | true or false (on/off also work) | droidline wifi false |
| A yes/no option | The option alone means true | droidline apps --system |
| A list of names | Comma-separated | droidline notify_filter com.android.chrome,com.google.android.gm |
Candidates for which | field=value pairs | droidline which text="Log in" id=main_tab |
Steps for batch | JSON in single quotes | droidline 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:
| Option | Meaning |
|---|---|
--device NAME, -d NAME | The phone to use. Needed when more than one is online. |
--json | Print the server's raw reply as one JSON line. |
--addr HOST:PORT | Server address. Default 127.0.0.1:8780. |
--token TOKEN | Client token, for a server on another machine. |
--home DIR | Settings 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 returns | It prints | Example |
|---|---|---|
| one value | the value alone | droidline exists text OK prints true |
| nothing | ok | droidline back |
| several fields | one JSON line | droidline battery prints {"charging":true,"level":87,"temperature":31.5} |
| a dump | indented JSON, or the file name when you give one | droidline dump screen.json |
| a screenshot | the file name and size | after-login.png (1080x2400) |
Errors go to standard error, so $(...) only captures real output.
Exit codes
| Code | Meaning |
|---|---|
0 | The command succeeded. A condition that answers false is still a success. |
1 | The command failed: the element was not found, the phone is offline, the server rejected a parameter. |
2 | The 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 $triggerUse full paths in scheduled jobs: they run with a smaller PATH than your terminal.
Setup commands
Besides phone commands, the CLI manages the server:
| Command | What it does |
|---|---|
droidline serve | Run the server. Keep it open. |
droidline pair | Show a QR code for pairing a phone. |
droidline pair <code> [--name NAME] | Approve the phone that shows this 6-digit code. |
droidline devices | List paired phones and their state. |
droidline rename <id> <name> | Give a phone a new name. |
droidline revoke <device> | Remove a phone's pairing. |
droidline doctor | Check the setup and print the settings folder. |
droidline token create|list|revoke | Client tokens for using the server from another machine. |
droidline relay set|status|off | Reach phones on mobile data through your relay. |
droidline proxy add|list|remove | Saved upstream proxies for the per-app proxy. |
droidline webhook secret | The signing secret for notification webhooks. |
droidline on_notification [--package P] | Print each notification as a JSON line until you stop it. |
droidline mcp | Run the MCP server for AI agents. |
droidline version | Print the version. |