2025-04-18 16:10:44 +03:00

3.7 KiB
Vendored

Events

Script notes can be triggered by events. Note that these are backend events and thus relation need to point to the "JS backend" code note.

Global events

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.

LabelDescription
run

Defines on which events script should run. Possible values are:

  • frontendStartup - when Trilium frontend starts up (or is refreshed), but not on mobile.
  • mobileStartup - when Trilium frontend starts up (or is refreshed), on mobile.
  • backendStartup - when Trilium backend starts up
  • hourly - run once an hour. You can use additional label runAtHour to specify at which hour, on the back-end.
  • daily - run once a day, on the back-end
runOnInstanceSpecifies that the script should only run on a particular Trilium instance.
runAtHourOn 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 - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it).

RelationDescription
runOnNoteCreationexecutes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script.
runOnChildNoteCreationexecutes when new note is created under the note where this relation is defined
runOnNoteTitleChangeexecutes when note title is changed (includes note creation as well)
runOnNoteContentChangeexecutes when note content is changed (includes note creation as well).
runOnNoteChangeexecutes when note is changed (includes note creation as well). Does not include content changes
runOnNoteDeletionexecutes when note is being deleted
runOnBranchCreationexecutes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.
runOnBranchChangeexecutes when a branch is updated. (since v0.62)
runOnBranchDeletionexecutes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).
runOnAttributeCreationexecutes when new attribute is created for the note which defines this relation
runOnAttributeChangeexecutes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted