Automations and apps
A folder can fetch records from another system, send records to it, and do small jobs when something happens. All of it is plain text in three folders inside your folder:
| Folder | One file is | It says |
connectors/ | a connector | one request to a server, and where its records go |
actions/ | an action | steps, done in order |
automations/ | an automation | when to run an action |
Nothing runs until you have read what it will do and allowed it. The quickest start is a ready-made one from Settings › Automations › Gallery.
Fetch records from another system
#A connector is a .self file of set lines:
~~~ selfscribe
set url https://crm.example/api/customers
set header Authorization: Bearer {secret:crm}
set pick data
set map email contact.email
set write merge id
set output data/customers.csv
~~~
# Customers, fetched
| Line | What it does |
set url | The address, https://, or http://localhost for a server on this computer. |
set method | GET unless you say POST, PUT, PATCH or DELETE. |
set header, set body | A header, one line each, and what is sent. {name} takes a record's cell. |
set pick data | Where the list is in the answer. |
set map email contact.email | A column of yours, and where its value is in each item. |
set where, set sort, set limit | Keeps, orders and counts the rows. |
set output | Where the records go: a .csv, .tsv or .json file, or a document. |
set write | replace, append, merge id to keep your own columns, or mirror id to remove what the server dropped. |
set pages 10 | Fetches a list that comes in pages. |
A key or a token never goes in the file. Save it in Settings › Automations › Secrets under
a name, and write {secret:NAME} where it belongs. It is kept in the system keychain.
Do things in order with an action
#An action is steps, one set step line each:
~~~ selfscribe
set step call customer-out
set step set-cell data/customers.csv name = {name} | id = {reply.id}
set step notify {name} sent: id {reply.id}
~~~
# Send a customer, keep the id
| Step | What it does |
call | Runs a connector. Its answer is {reply}, and {reply.id} a value in it. |
add-row | Adds a record at the end of a .csv or .tsv file. |
set-cell, set-cells | Changes the first record that matches, or every one. |
ask | Asks a question with buttons. It stays until it is answered. |
append, prepend, write, create | Adds a line to a file, or writes the file. |
notify, open, copy | Shows a message, opens a file, or copies text. |
The parts of a step are cut at | . Each button of a question names the action it runs:
set step add-row data/log.csv {today} | {time} | started
set step ask Night, 21:30 | Took all = took-night | Snooze 15 min = snooze 15 | Skip
A send that cannot reach the server is kept and tried again, and goes on from the step where it stopped. Look first on any action shows what would be sent and written, and does neither.
Run it when something happens
#An automation names a moment and an action:
~~~ selfscribe
set when record added data/customers.csv
set do send-customer
~~~
set when | The moment |
record added SOURCE | A record is added through a view. |
record changed quotes status to won | A cell changes, here to one value. |
record deleted SOURCE | A record is deleted. |
comment added, document saved, file changed FILE | Comments, saves and files. |
daily at 09:00, every 30 minutes | A time, while the folder is open. |
schedule data/reminders.csv | Once a day per record, at the time in its at column. |
open | The folder is opened. |
The action knows the moment's names: {today}, {time} and {weekday} always, and from a
record each cell by its column's name, with {was} and {value} for a changed cell.
An automation is off until you switch it on in Settings › Automations. The first time an action runs, the app shows what it will do and asks: Run once, or Always allow in this folder.
Put a button in a document
#Add this rule to the document, then write [[Fetch the customers|fetch-customers]]:
inline [[_|_]] -> span.self-button data-self-action=_2 _1
Pressing the button runs actions/fetch-customers.self. A view can put a button in each row
instead: view: data/plants.csv as table button Watered runs watered.
Show a folder as an app
#A folder can open as an app: a few screens, a bar at the bottom to move between them, and
nothing of the editor around them. Each screen is an ordinary document. Add app.self at the
top of the folder:
~~~ selfscribe
set app Daily plan
set screen Today = today.self | check
set screen Journal = journal.self | book
set screen Progress = progress.self | chart
set accent #2f7d6b
~~~
Each set screen line is a tab of the bar, up to five, with its label, its document and an
icon. View › Open this folder as an app shows the app, and the pencil at the top right goes
back to the editor. A screen holds anything a document can hold. What makes it feel like an
app:
- views drawn
plain, lists to tick, tiles of totals and forms, - buttons that run actions, and questions with buttons at a time of day,
- links to the other documents of the folder.
View › Show this document as a page by itself does the same for one document.
Give the app to someone
#File › Package this app for a web host… saves one .zip. Unpack it on any web host, and
the address of that folder is the app. It has the app's own name, colour and icon, so a phone
that installs it shows Daily plan, and it works without a connection once opened.
What each person enters is kept in their own browser, on their device. To share records between people, share the folder itself with sync.