Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

3.9 KB
Raw Blame

Local API

General › Local API lets your own scripts and tools on the same computer use TwinDesk: send files to the connected device and put text on the clipboard. It's off until you switch it on, on the Mac, Windows and Linux (one-to-one, not Multi-device yet).

Where it is

While it's on, TwinDesk writes local-api.json in its own folder (the path is shown under the switch), readable only by you:

{ "url": "http://127.0.0.1:52817/v1/", "port": 52817, "key": "…48 hex characters…" }

The port and the key change every time it starts, so read the file each time. Switching it off removes the file and closes the port.

Calls

Every call needs Authorization: Bearer <key>. Bodies are JSON (Content-Type: application/json).

Call Body Answer
GET /v1/status {"connected": true, "device": "Pixel"}
POST /v1/send {"paths": ["/full/path/a.pdf", …]} {"ok": true, "status": "sent"}, or "queued" when the device isn't connected and Keep files to send is on
POST /v1/clipboard {"text": "…"} {"ok": true}; it then goes to the other device by Clipboard's own rules
POST /v1/task-alert/start {"title": "Build"} {"ok": true, "id": "…32 hex characters…"} when a connected phone has Task alerts on
POST /v1/task-alert/finish {"id": "…", "ok": true} {"ok": true} when the completion was submitted to that same connection
POST /v1/task-alert/cancel {"id": "…"} {"ok": true}; drops a pending watch without alerting the phone
f="$HOME/Library/Application Support/TwinDesk/local-api.json"   # the path under the switch
url=$(jq -r .url "$f"); key=$(jq -r .key "$f")
curl -s -H "Authorization: Bearer $key" "${url}status"
curl -s -H "Authorization: Bearer $key" -H 'Content-Type: application/json' \
  -d '{"paths":["/Users/me/Desktop/report.pdf"]}' "${url}send"

Terminal task alerts

On the computer (Mac, Windows or Linux, one-to-one or Multi-device), turn on General › Local API. On the phone, turn on Notifications › Task alerts for that computer and allow TwinDesk to post notifications. Then put twindesk-notify before a command, and the phone tells you when it finishes or fails:

twindesk-notify make                          # the label is "Terminal task"
twindesk-notify --title "Build" -- npm run build

General › Local API shows the launcher's full path with a Copy button. It is in TwinDesk's own folder (bin/twindesk-notify, or bin\twindesk-notify.cmd on Windows) and runs with TwinDesk's own runtime, so no Node.js is needed. Add that bin folder to your PATH to type just twindesk-notify. TwinDesk writes the launcher again each time the API starts, so it follows the app when it moves or updates.

The label can have up to 80 characters. The command runs here with its normal input, output, exit code and signal. On Windows anything but an .exe runs through cmd, so npm and gradlew work as they do in a terminal. Only the label and success or failure go to the phone, never the command or its output. The address and key are read from local-api.json on each call.

Every connected phone that turned Task alerts on gets the alert, on the session it asked on. A watch expires after 24 hours, and the computer holds up to 32 at once. With no phone left, pending watches are dropped. The command still runs when the API is off or the alert is refused, and the wrapper prints the reason. Interrupting the wrapper cancels its alert. The phone decides whether to show it (at most 8 a minute).

What it refuses

  • Anything not from this computer: it listens on 127.0.0.1 only, and the Host must be 127.0.0.1:<port> or localhost:<port>.
  • Anything a browser sends (an Origin, Referer or Sec-Fetch-* header), so a web page can't reach it even if it guesses the port.
  • A missing or wrong key, a body that isn't JSON, more than 256 KB, paths that aren't absolute or don't exist.