# CLI

Legato comes with a command-line tool, `legato`, inside the app. A shell script, a launchd or cron job, or you at a terminal can use it to write and read pages, arrange the sidebar, add a service's pages from a template, and add to History and lists. It takes a page as JSON from a file or stdin and answers in JSON, so a script can check what happened.

Secrets are the exception. `legato secret` passes its arguments to the app's own `secret` command, which answers in plain text. You can also run that command as `/Applications/Legato.app/Contents/MacOS/Legato secret`.

The table below lists every command. Each group has a page with its arguments, its output and an example:

- [Pages](https://legatobar.com/docs/cli-pages.md): `set`, `get`, `list`, `delete` and `schema`.
- [Sidebar](https://legatobar.com/docs/cli-sidebar.md): `sidebar` prints the arrangement, and `arrange` changes it.
- [Templates and install](https://legatobar.com/docs/cli-templates.md): `templates` and `install`, with a dry run.
- [History and rows](https://legatobar.com/docs/cli-history.md): `history` reports what's kept, and `rows` adds, lists and deletes rows.
- [Lists](https://legatobar.com/docs/cli-lists.md): `lists`, `lists set` and `lists delete`.
- [legato mcp](https://legatobar.com/docs/cli-mcp.md): The server an agent's app starts.
- [legato secret](https://legatobar.com/docs/cli-secret.md): Credentials in the Keychain, or linked from 1Password.

## The legato command

The `legato` command works from a shell or a script. It makes the same checks as the [MCP tools](https://legatobar.com/docs/mcp-tools.md) and gives the same answers:

| Command | Does |
| --- | --- |
| `legato set <id> [file]` | Writes a page from a JSON file, or from stdin. Same as `set_page`. |
| `legato get <id>` | Prints a page with its version and status. |
| `legato list` | Lists the pages. |
| `legato delete <id>` | Moves a page to the Trash. |
| `legato schema [part]` | The page format: `page`, `sources`, `rules`, `actions`, `period`, `params`, `notify`, `title_from` or a card type. |
| `legato preview [file]` | Fills a page's cards from a sample answer, offline, as [`preview_page`](https://legatobar.com/docs/mcp-tools.md#checking-a-pages-sources) does. It reads `{"page_id" or "page", "source", "sample"}` from the file or stdin. |
| `legato sidebar` | How the sidebar is arranged. Same as `get_sidebar`. |
| `legato arrange [file]` | Changes the arrangement from a JSON object in a file or stdin: `op` names the tool (`set_collection`, `delete_collection`, `set_section`, `delete_section` or `move_page`), and the rest are its arguments. |
| `legato templates [service]` | Lists the bundled templates, or shows one service's template with its inputs. Same as `get_templates`. |
| `legato install <service> --set name=value ... [--dry-run] [--copy]` | Adds a service's pages from its template. With `--dry-run` it shows what it would do and writes nothing. With `--copy` it adds a numbered set beside pages already there. Same as `install_template`. |
| `legato rows add\|list\|delete <dataset>` | Adds, lists or deletes a history's rows. Same as `add_rows`, `list_rows` and `delete_rows`; see [History](https://legatobar.com/docs/history-rows.md#legato-rows). |
| `legato history` | Every history's status and size, and every page's sparkline readings. Same as `get_history`. |
| `legato lists` | Every list, with its entries and the pages that check it. Same as `get_lists`. |
| `legato lists set <name> [--if-missing] [file\|-]` | Creates or replaces a list from a file or stdin: one entry per line, or a JSON array of strings. With `--if-missing`, a list that already exists is kept. Same as `set_list`. |
| `legato lists delete <name>` | Deletes a list. Same as `delete_list`. |
| `legato version` | The version of `legato`, the app it belongs to, whether the app is running, and the Pages folder. |
| `legato mcp` | Runs the MCP server on stdio. |
| `legato secret <command> ...` | Saves, lists or deletes a source's secret. It runs the app's own `secret` command with the same arguments, and answers in plain text; see [legato secret](https://legatobar.com/docs/cli-secret.md). |

`--if-match <version>` with `set` or `delete` acts only if the page is still at that version. `legato help` prints the usage.

See [Your first page from a shell](#your-first-page-from-a-shell) below, and [Scripts](https://legatobar.com/docs/scripts.md) for worked examples that keep pages current.


## Your first page from a shell

You don't need an agent to write a page. Save one as `budget.json`:

```json
{
  "title": "Budget",
  "icon": "dollarsign.circle",
  "cards": [
    { "id": "month", "type": "pacing", "label": "October spend",
      "value": 2140, "target": 3200, "elapsed": 0.55, "unit": "USD" },
    { "id": "top", "type": "list", "label": "Largest this week",
      "items": ["Costco · $212", "Delta Air Lines · $189"] },
    { "id": "note", "type": "text", "body": "Dining is 18% over pace.", "tone": "warning" }
  ]
}
```

and write it with `legato set`:

```bash
/Applications/Legato.app/Contents/Helpers/legato set budget budget.json
```

```json
{
  "changed" : true,
  "collection" : null,
  "created" : true,
  "id" : "budget",
  "loaded" : {
    "loaded_at" : "2026-10-27T21:04:11.482Z",
    "ok" : true
  },
  "placement" : "ungrouped",
  "version" : "33527b6dde59dde2"
}
```

`legato set budget` with no file reads the page from stdin, so a script can pipe one in. If Legato refuses the page, `legato` prints `{"error": {"code", "message"}}` and exits with status 1, and the page stays as it was. `legato get budget` prints it back, `legato list` lists your pages, and `legato --help` lists the rest. See [The legato command](https://legatobar.com/docs/cli.md#the-legato-command).

To keep the page current, run the same command whenever the numbers change, from launchd, cron or a script. Every write replaces the whole page. Writing an identical page again keeps its version, and `changed` is `false`; the page's update time moves on, so its footer shows the job is still running. [Scripts](https://legatobar.com/docs/scripts.md) has complete examples.

You can also skip `legato` and save the file yourself in `~/Library/Application Support/Legato/Pages`, as `budget.json`. Write it to a temporary file in the same folder and rename it into place, so Legato never reads half a file. Legato shows the page as soon as the file appears; if the file has a mistake, the page says what's wrong.

## Executable, output and status

The `legato` command is at `/Applications/Legato.app/Contents/Helpers/legato`. The examples in these pages write `legato` for that path. Pages live in `~/Library/Application Support/Legato/Pages`.

Answers are JSON on stdout, printed over several lines with the keys in alphabetical order. `legato help` prints plain text, and `legato mcp` speaks the MCP protocol. A command that works exits with status 0.

A refusal is `{"error": {...}}` on stdout with exit status 1. The error has a `code` and a `message`, and sometimes `details`. A command with a missing argument is refused with `invalid_arguments`. For `templates` and `install` the code is `failed`, and the message says how to call them. `legato secret` keeps the app command's output and exit status; see [legato secret](https://legatobar.com/docs/cli-secret.md#output-and-exit-status). A command that `legato` doesn't know prints an error and the usage to stderr and exits with status 2.

A command that takes a `[file]` reads stdin when the file is left out. `lists set` also reads stdin when the file is `-`. `set`, `arrange` and `rows add` look for a file named `-`.

## Example

```bash
legato version
legato help
```

`version` prints where `legato` found the app and its pages:

```json
{
  "app" : "/Applications/Legato.app",
  "bundle_id" : "com.legatobar.mac",
  "pages" : "/Users/you/Library/Application Support/Legato/Pages",
  "running" : true,
  "version" : "1.0"
}
```

`app` is `null` when `legato` can't find the app. `help` prints the usage, which begins with `Usage:`. So do `legato --help` and `legato` with no arguments.
