cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / docs / files / scripts.md
scripts.md 8.8K rendered
1---2title: "Scripts"3sidebar_position: 64---56# Scripts78Four commands read and change a `.012` workbook without the screen, for9shell scripts, cron jobs, Makefiles, nushell pipelines and10[agents](../agents/README.md), which also have `012 describe`:1112```sh13012 get budget.012 B7 # a cell's value, as the sheet shows it14012 get budget.012 'Q3 plan'!A1:C9 --format csv15012 set budget.012 B7 '=SUM(A1:A6)' B8 1200 # type entries, then save16012 recalc budget.012 # recalculate, save, list the errors17012 export budget.012 budget.xlsx # what File > Download writes18```1920None of them runs a program or reaches the network unless a flag asks:21see [Notebooks and JEV functions](#notebooks-and-jev-functions). The flags22and exit statuses of every command are in23[Command line](../reference/command-line.md).2425## References2627A reference names cells as a formula does, with the sheet in front when28it isn't the one shown when the file was saved:2930| Reference | Names |31|---|---|32| `B7`, `A1:C9`, `A:A`, `$B$7` | Cells of the sheet shown when the file was saved |33| `Q3!B7`, `'Q3 plan'!A1:C9` | Cells of the sheet named, quoted as in formulas when the name has spaces (the shell needs quotes around it too) |34| `Sales` | A [named range](../formulas/references.md), or a [table](../sheets/tables.md) or notebook output, header row included, so JSON and NUON name its columns |35| `Sales[Amount]`, `Sales[[#Headers],[Amount]]` | A table's cells by a [structured reference](../formulas/references.md#tables-by-column-name), as a formula outside the table reads them: `Sales[Amount]` is the column's data, without its header |36| `Q3`, `Q3!` | The whole sheet, from A1 to its last cell with contents |3738A reference that names nothing says what the workbook has: `no sheet39named "Q4" (sheets: Q1, Q2, Q3)`.4041## get4243`012 get file ref` writes the value of a cell, or a table of a range or44sheet (the sheet shown when there's no reference). `--format` picks the45form:4647| Format | One cell | A range or sheet |48|---|---|---|49| `text`, the default | As the cell shows it: `$1,200.00`, `9/29/2026`, `#DIV/0!` | Aligned columns, numbers to the right |50| `csv`, `tsv` | One line | Rows as shown, in the workbook's [locale](../sheets/locale.md), as a CSV download |51| `json` | The [value with its type](../reference/json.md#values): `3.5`, `"00123"`, `true`, `null` for a blank cell, `{"currency": 3.5}`, `{"date": "2026-09-29"}` | A list of records named by the range's first row |52| `nuon` | The value with its nushell type: a date, a file size, a duration | A nushell table named by the range's first row |5354JSON and NUON type values by their cells' formats, JSON as the55[values](../reference/json.md#values) agents read and NUON as a56[NUON download](../nushell/types.md) does, and take the columns' names57from the range's first row, as a table in 012 has its header there.58`--no-header` names the columns by their letters instead (`A`, `B`) and59makes the first row a record too. A filter doesn't hide rows from `get`:60a script reads all the range holds.6162`--input` writes what was typed rather than what it computes: a63formula, or an entry as the file stores it (numbers and dates in64en-US's form whatever the workbook's locale), so65`012 get budget.012 B7 --input` prints `=SUM(A1:A6)`.6667In nushell, NUON comes back as a table with its types:6869```nu70012 get budget.012 A1:C9 --format nuon | from nuon | where amount > 10071012 get budget.012 B7 --format nuon | from nuon # a number, not a string72```7374## set7576`012 set file ref input [ref input ...]` types each input into its cell,77in order, as one change, and saves the file atomically: into a temporary78file beside it, renamed over it once complete. An empty input clears the79cell's contents, keeping its formatting and note, as Delete does. A file80that doesn't exist is created, as `012 budget.012` does.8182Inputs are what the file stores, not what the sheet's locale types: `1.5`83and `=ROUND(A1, 2)` in every workbook, so a script means the same in a84de-DE workbook as in an en-US one. Entries that imply a format (`$1,200`,85`12%`, `2026-09-29`) set it, as typing them does.8687`--value` takes each input as a [value with its type](../reference/json.md#values),88in JSON or NUON, for what typing has no entry for: sizes, durations,89other currencies, text that looks like a number. `--table ref` writes90the table on standard input (NUON or JSON, a list of records) with its91header at `ref`, each column formatted as its values' type, as92importing it would, before the entries:9394```sh95012 set budget.012 --value B7 '{"currency": 12.5, "symbol": "€"}' C7 1.5kb D7 '"00123"'96ls | select name size modified | to nuon | 012 set files.012 --table A197```9899`set` stops, and leaves the file as it was, on the first input a cell100can't take, naming the cell:101102| Refused | Says |103|---|---|104| A formula that doesn't parse | `Sheet1!B7: Expected , or ) in SUM, at character 11 of =SUM(A1:A6` |105| An entry a validation rule rejects | the rule's help, as the context line would |106| A cell of an array's result, a pivot table, a linked file or a notebook's output | the same message as on the screen |107| A cell in a [protected range](../sheets/notes-protection.md) | `Sheet1!B7 is protected (B1:B9): --force sets it anyway` |108| A reference to a range, not one cell | `A1:B2 is the range A1:B2: name one cell` |109110An entry a rule only marks invalid is set, with a warning on standard111error. An input that starts with `--` (a flag's shape) comes after `--`:112`012 set budget.012 -- A1 --`.113114`--dry-run` checks the entries the same way but saves nothing, and115prints what would change as [`012 diff`](git.md#012-diff) would:116117```118$ 012 set budget.012 B7 '=SUM(A1:A6)' B8 1200 --dry-run119Sheet1!B7 input "=SUM(A1:A5)" → "=SUM(A1:A6)"120Sheet1!B8 input + 1200121```122123`--format json` writes the result, the changes as records, instead124([JSON output](../reference/json.md#set)).125126## recalc127128`012 recalc file` recomputes every formula, saves the file (leaving it129untouched when nothing it stores changed) and lists each formula showing130an error, one a line, with what the screen's context line says about it:131132```133Q3!B7 #DIV/0! Division by zero in B6/C6134Q3!D2 #N/A JEV functions need --jev and an API key to be answered135```136137It exits 1 when any cell shows an error or a formula reads its own cell,138so `012 recalc budget.012 && deploy` stops on a broken sheet. `--format139json` writes the list as [JSON](../reference/json.md#recalc).140141## export142143`012 export file out [ref]` writes the workbook in another format, as144File > Download does: the format by `out`'s extension or `--format`145(`csv`, `tsv`, `xlsx`, `sqlite`, `json`, `nuon`, `html`). XLSX gets every146sheet; the others get the sheet shown, or `ref`'s range or sheet. A147[web page](README.md#web-pages) of a range draws the charts whose corner148is in it; `--chart` writes one chart alone, found by its number on the149sheet (1 for the first) or its title:150151```sh152012 export budget.012 q3.html 'Q3 plan'!A1:F20153012 export budget.012 spending.html Q3 --chart 'Spending by month'154```155 SQLite writes156a table named by `--table`, replacing one of that name. Formulas are157written as their values where the format has no formulas, and a note on158standard error says how many. CSV, TSV, JSON and NUON leave out the rows159a filter hides, as a download does.160161## Notebooks and JEV functions162163A `.012` file stores what was typed and computes the rest, so a few164things need more than the file:165166- **[Notebook](../nushell/notebooks.md) outputs** are kept in the file167 as their cells last left them, and these commands read them as saved,168 sent to sheets as on the screen; `get` notes on standard error when169 the sheet it reads has an output the file doesn't hold (never run, or170 too large to save). `--notebooks` runs every notebook's171 code cells first, each after the cells it reads, as F9 does; a cell172 that fails stops the rest of its notebook, and is reported. A cell173 reading `$selection` fails, having no selection to read.174- As on the screen, a notebook175 [saved on another computer](../nushell/notebooks.md#saving-and-trust)176 asks first: `--notebooks` refuses it unless `--trust` gives the answer177 Run would, and `recalc --notebooks --trust` saves that trust in the178 file as the screen does, so later runs don't need it. `shell = off` in179 the [configuration](../reference/config.md#shell) turns `--notebooks`180 off, `shell = on` runs every file's cells, each cell stops after181 `nu-timeout`, and saving keeps as much of the outputs as182 `nu-save-cell-kb` and `nu-save-notebook-kb` allow.183- **[Linked files](following.md)** are followed only on the screen; their184 regions are empty here.185- **[JEV functions](../formulas/jev.md)** ask a hosted model over the186 network, and show `#N/A` here unless `--jev` asks it, with the API key187 from the environment, the credential store or `jev-api-key-command`.188189`get`, `recalc`, `export` and `describe` take these flags; `set`190computes values only to check entries.