Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions docs/User Guide/User Guide/Scripting/Backend scripts/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,11 @@

Global events are attached to the script note via label. Simply create e.g. "run" label with some of these values and script note will be executed once the event occurs.

<table>
<thead>
<tr>
<th>Label</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code spellcheck="false">run</code></td>
<td><p>Defines on which events script should run. Possible values are:</p><ul><li><code spellcheck="false">backendStartup</code> - when Trilium backend starts up</li><li><code spellcheck="false">hourly</code> - run once an hour. You can use additional label <code spellcheck="false">runAtHour</code> to specify at which hour, on the back-end.</li><li><code spellcheck="false">daily</code> - run once a day, on the back-end</li></ul></td>
</tr>
<tr>
<td><code spellcheck="false">runOnInstance</code></td>
<td>Specifies that the script should only run on a particular&nbsp;<a class="reference-link" href="../../Advanced%20Usage/Configuration%20(config.ini%20or%20environment%20variables)/Trilium%20instance.md">Trilium instance</a>.</td>
</tr>
<tr>
<td><code spellcheck="false">runAtHour</code></td>
<td>On which hour should this run. Should be used together with <code spellcheck="false">#run=hourly</code>. Can be defined multiple times for more runs during the day.</td>
</tr>
</tbody>
</table>

| Label | Description |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Multiple run values are supported

A single script note can have multiple run label values because each scheduler event independently retrieves matching notes. Stating that the values are mutually exclusive and require separate script copies gives users unnecessary and incorrect configuration guidance.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `run` | Defines on which events script should run. Possible backend values are:<br>- `backendStartup` – when Trilium backend starts up<br>- `hourly` – run once an hour. You can use additional label `runAtHour` to specify at which hour, on the back-end.<br>- `daily` – run once a day, on the back-end<br><br>There are two frontend values:<br>- `frontendStartup` – when Trilium frontend starts up (e.g. browser reload)<br>- `mobileStartup` – when mobile frontend starts up. See [mobile frontend](../../../setup/mobile-frontend) <br>Note that all event values for run attributes are mutually exclusive. To get the same script to trigger on multiple events, create multiple copies of the script and assign each the key value pair you need. |
| `runOnInstance` | Specifies that the script should only run on a particular [Trilium instance](../../Advanced%20Usage/Configuration%20(config.ini%20or%20environment%20variables)/Trilium%20instance.md). |
| `runAtHour` | On which hour should this run. Should be used together with `#run=hourly`. Can be defined multiple times for more runs during the day. |
## Entity events

Other events are bound to some entity, these are defined as [relations](../../Advanced%20Usage/Attributes.md) - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it).
Expand Down Expand Up @@ -61,4 +43,4 @@ if (attr.value === "Health") {
} else {
note.removeLabel("color");
}
```
```