Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Script Tetheron from the command line

tether-cli is installed with the desktop package. It talks to the daemon over the session bus, so run it as your own user inside your desktop session. This page has recipes. Command-line tools lists every command and option.

Find the device id

Every command that acts on a phone takes its device id:

tether-cli devices
ID           NAME                     KIND     PAIRED  CONNECTED  BATTERY   STATE
5b7a19c04e2d Example Phone            phone    yes     yes        82%+      paired

Any prefix of the id that matches one device only is enough. If the prefix matches several devices, the command stops and lists them. In a script, use the twelve characters that devices prints. The examples below use 5b7a.

Check the result in a script

A command that fails prints the reason on standard error and exits with a non-zero status. Commands that wait for the phone (send, send-file, dial) report the phone’s answer:

if tether-cli send 5b7a +15550100 "Backup finished"; then
    echo "sent"
else
    echo "not sent" >&2
fi

send and send-file take --no-wait to return as soon as the request is queued.

pair and confirm ask a question on the terminal and refuse to run without one. Pass --yes only in a script where you have checked the six-digit code another way.

Follow events with watch

tether-cli watch prints one line for each event from the daemon until you press Ctrl+C:

watching org.tether.Daemon (Ctrl-C to stop)
device 5b7a19c04e2d Example Phone paired=true connected=true
5b7a19c04e2d changed: BatteryLevel=81
5b7a19c04e2d notification: [0|com.example.chat|12|null|10123] Chat — Ada: See you at six
5b7a19c04e2d message 4211 [t17] inbox +15550100: Are you there?
5b7a19c04e2d FileReceived: /home/you/Downloads/Tether/report.pdf
5b7a19c04e2d INCOMING CALL [7] ringing incoming Ada <+15550100> route=phone (answer with `tether-cli answer 5b7a19c04e2d`)
5b7a19c04e2d calls: none

Each event line starts with the first twelve characters of the device id, followed by the kind of event. Property changes read changed: and then Name=value pairs, with the property names from the D-Bus API.

Warning

The output of watch contains message texts, notification texts and phone numbers. Do not write it to a file that others can read.

React to events

watch writes each line as it happens, so you can pipe it into a loop and match on the event:

#!/bin/sh
# Opens every PDF the phone sends, and logs incoming calls.
tether-cli watch | while read -r id event rest; do
    case "$event" in
        FileReceived:)
            case "$rest" in
                *.pdf) xdg-open "$rest" ;;
            esac
            ;;
        INCOMING)
            logger -t tether "phone $id: incoming call"
            ;;
    esac
done

read -r id event rest splits each line into the device id, the first word of the event and the remainder. For FileReceived: the remainder is the path of the file.

To act on a property, match the changed: lines. This shows a desktop notification when the phone is fully charged:

tether-cli watch | while read -r id event rest; do
    case "$event $rest" in
        "changed: "*BatteryLevel=100*) notify-send "Phone charged" ;;
    esac
done

To keep a script like this running, start it with your desktop session, for example from a systemd user unit.

Ring the phone from a keyboard shortcut

Open the desktop’s keyboard settings, add a custom shortcut and set its command to:

tether-cli ring 5b7a

The phone rings for at most 60 seconds. tether-cli ring 5b7a stop ends it earlier.

Send files from the file manager

In Nemo (Cinnamon), create ~/.local/share/nemo/actions/send-to-phone.nemo_action:

[Nemo Action]
Name=Send to phone
Comment=Send the selected files to the phone with Tetheron
Exec=tether-cli send-file --no-wait 5b7a %F
Icon-Name=document-send-symbolic
Selection=notnone
Extensions=nodirs;

In Files (Nautilus), create the script ~/.local/share/nautilus/scripts/Send to phone:

#!/bin/sh
# Sends the selected files to the phone with Tetheron.
printf '%s\n' "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" |
while IFS= read -r path; do
    [ -f "$path" ] && tether-cli send-file --no-wait 5b7a "$path"
done

Make it executable:

chmod +x ~/.local/share/nautilus/scripts/"Send to phone"

Right-click a file and choose Send to phone, in Nautilus under Scripts. The transfers appear on the Files tab of the Tetheron app, where you can follow or cancel them.

Send text to the phone’s clipboard

clipboard send reads standard input when you give it no text:

tether-cli clipboard 5b7a send "https://example.org/a-long-link"
hostname -I | tether-cli clipboard 5b7a send

tether-cli clipboard 5b7a get prints the last text that the phone sent.

Send a text message when a job ends

make backup && tether-cli send 5b7a +15550100 "Backup finished on $(hostname)"

The message goes out as an SMS from the phone’s default SIM. Add --sim with a subscription id from tether-cli status 5b7a to choose another.

Silence the phone for a meeting

tether-cli dnd 5b7a priority
tether-cli media 5b7a pause
tether-cli volume 5b7a music 0

tether-cli dnd 5b7a all switches Do Not Disturb off again. playerctl can control the phone’s playback too. See Control media and the phone.

Save the newest screenshot from the phone

id=$(tether-cli photos 5b7a screenshot --limit 1 | grep -v '^index' | awk 'NR==1 {print $1}')
cp "$(tether-cli fetch 5b7a "$id" | tail -n 1)" ~/Pictures/

photos prints the newest items first, with the item id in the first column. The grep drops the notice that photos prints when it has to ask the phone first. fetch downloads the original into the daemon’s cache and prints its path on the last line. Copy the file and leave the original where it is, because the cache belongs to the daemon.

Beyond tether-cli

Everything tether-cli does goes through the daemon’s interface on the session bus, under the name org.tether.Daemon. busctl --user reaches the parts that have no command. The D-Bus API describes every method, property and signal.

To address a daemon that runs under another bus name, set TETHER_BUS_NAME. See Debug Tetheron.