docs/Script API/interfaces/Frontend_Script_API.Api.html
interface Api {
$container: null | JQuery<HTMLElement>;
BasicWidget: typeof BasicWidget;
bindGlobalShortcut: (
keyboardShortcut: string,
handler: null | Handler,
namespace?: null | string,
) => void;
createLink: (
notePath: undefined | string,
options?: CreateLinkOptions,
) => Promise<JQuery<HTMLElement>>;
createNoteLink: (
notePath: undefined | string,
options?: CreateLinkOptions,
) => Promise<JQuery<HTMLElement>>;
currentNote: FNote;
dayjs: __module;
formatDateISO: (date: Date) => string;
formatNoteSize: (size: number) => string;
formatSize: (size: number) => string;
getDayNote: (date: string) => Promise<null | FNote>;
getMonthNote: (month: string) => Promise<null | FNote>;
getQuarterNote: (quarter: string) => Promise<null | FNote>;
getTodayNote: () => Promise<null | FNote>;
getWeekFirstDayNote: (date: string) => Promise<null | FNote>;
getWeekNote: (week: string) => Promise<null | FNote>;
getYearNote: (year: string) => Promise<null | FNote>;
logMessages: Record<string, string[]>;
logSpacedUpdates: Record<string, default>;
NoteContextAwareWidget: typeof NoteContextAwareWidget;
originEntity: unknown;
parseDate: (str: string) => Date;
protectNote: (
noteId: string,
protect: boolean,
includingSubtree: boolean,
) => Promise<void>;
protectSubTree: (
noteId: string,
protect: boolean,
includingSubtree: boolean,
) => Promise<void>;
randomString: (len: number) => string;
RightPanelWidget: typeof RightPanelWidget;
setupElementTooltip: ($el: JQuery<HTMLElement>) => void;
showConfirmDialog: (message: string) => Promise<unknown>;
showError: (message: string, delay?: number) => void;
showInfoDialog: (message: string) => Promise<unknown>;
showMessage: (message: string, delay?: number) => void;
showPromptDialog: (props: PromptDialogOptions) => Promise<null | string>;
startNote: FNote;
triggerCommand: <K extends keyof CommandMappings>(
name: K,
_data?: CommandMappings[K],
) => undefined | null | Promise<unknown>;
triggerEvent: <K extends EventNames>(
name: K,
data: EventData<K>,
) => undefined | null | Promise<unknown>;
waitUntilSynced: () => Promise<void>;
activateNewNote(notePath: string): Promise<void>;
activateNote(notePath: string): Promise<void>;
addButtonToToolbar(opts: AddToToolbarOpts): void;
addTextToActiveContextEditor(text: string): void;
getActiveContext(): NoteContext;
getActiveContextCodeEditor(): Promise<unknown>;
getActiveContextNote(): FNote;
getActiveContextNotePath(): null | string;
getActiveContextTextEditor(): Promise<unknown>;
getActiveMainContext(): NoteContext;
getActiveNoteDetailWidget(): Promise<default>;
getComponentByEl(el: HTMLElement): default;
getInstanceName(): string;
getMainNoteContexts(): NoteContext[];
getNote(noteId: string): Promise<null | FNote>;
getNoteContexts(): NoteContext[];
getNotes(
noteIds: string[],
silentNotFoundError?: boolean,
): Promise<FNote[]>;
log(message: string): void;
openSplitWithNote(notePath: string, activate: boolean): Promise<void>;
openTabWithNote(notePath: string, activate: boolean): Promise<void>;
refreshIncludedNote(includedNoteId: string): void;
reloadNotes(noteIds: string[]): Promise<void>;
runAsyncOnBackendWithManualTransactionHandling(
func: Func,
params: unknown[],
): unknown;
runOnBackend(func: Func, params: unknown[]): unknown;
searchForNote(searchString: string): Promise<null | FNote>;
searchForNotes(searchString: string): Promise<FNote[]>;
setHoistedNoteId(noteId: string): void;
}
$containerBasicWidgetbindGlobalShortcutcreateLinkcreateNoteLinkcurrentNotedayjsformatDateISOformatNoteSizeformatSizegetDayNotegetMonthNotegetQuarterNotegetTodayNotegetWeekFirstDayNotegetWeekNotegetYearNotelogMessageslogSpacedUpdatesNoteContextAwareWidgetoriginEntityparseDateprotectNoteprotectSubTreerandomStringRightPanelWidgetsetupElementTooltipshowConfirmDialogshowErrorshowInfoDialogshowMessageshowPromptDialogstartNotetriggerCommandtriggerEventwaitUntilSynced
activateNewNoteactivateNoteaddButtonToToolbaraddTextToActiveContextEditorgetActiveContextgetActiveContextCodeEditorgetActiveContextNotegetActiveContextNotePathgetActiveContextTextEditorgetActiveMainContextgetActiveNoteDetailWidgetgetComponentByElgetInstanceNamegetMainNoteContextsgetNotegetNoteContextsgetNoteslogopenSplitWithNoteopenTabWithNoterefreshIncludedNotereloadNotesrunAsyncOnBackendWithManualTransactionHandlingrunOnBackendsearchForNotesearchForNotessetHoistedNoteId
$container: null | JQuery<HTMLElement>
Container of all the rendered script content
BasicWidget: typeof BasicWidget
bindGlobalShortcut: (
keyboardShortcut: string,
handler: null | Handler,
namespace?: null | string,
) => void
- keyboardShortcut: string
e.g. "ctrl+shift+a"
- handler: null | [Handler](../types/Frontend_Script_API._internal_.Handler.html)
- namespace: null | string = null
specify namespace of the handler for the cases where call for bind may be repeated. If a handler with this ID exists, it's replaced by the new handler.
createLink: (
notePath: undefined | string,
options?: CreateLinkOptions,
) => Promise<JQuery<HTMLElement>>
Create a note link (jQuery object) for given note.
- notePath: undefined | string
(or noteId)
- options: [CreateLinkOptions](Frontend_Script_API._internal_.CreateLinkOptions.html) = {}
- jQuery element with the link (wrapped in )
createNoteLink: (
notePath: undefined | string,
options?: CreateLinkOptions,
) => Promise<JQuery<HTMLElement>>
currentNote: FNote
Note where the script is currently executing, i.e. the note where the currently executing source code is written.
dayjs: __module
day.js library for date manipulation. See https://day.js.org for documentation
formatDateISO: (date: Date) => string
this is producing local time! *
- date: Date
date in YYYY-MM-DD format
formatNoteSize: (size: number) => string
- size: number
in bytes
formatted string
formatSize: (size: number) => string
- size: number
in bytes
formatted string
getDayNote: (date: string) => Promise<null | FNote>
Returns day note for a given date. If it doesn't exist, it is automatically created.
- date: string
e.g. "2019-04-29"
getMonthNote: (month: string) => Promise<null | FNote>
Returns month-note. If it doesn't exist, it is automatically created.
- month: string
e.g. "2019-04"
getQuarterNote: (quarter: string) => Promise<null | FNote>
Returns quarter note for given date. If such a note doesn't exist, it is automatically created.
getTodayNote: () => Promise<null | FNote>
Returns date-note for today. If it doesn't exist, it is automatically created.
getWeekFirstDayNote: (date: string) => Promise<null | FNote>
Returns day note for the first date of the week of the given date. If it doesn't exist, it is automatically created.
- date: string
e.g. "2019-04-29"
getWeekNote: (week: string) => Promise<null | FNote>
Returns week note for given date. If such a note doesn't exist, it is automatically created.
getYearNote: (year: string) => Promise<null | FNote>
Returns year-note. If it doesn't exist, it is automatically created.
- year: string
e.g. "2019"
logMessages: Record<string, string[]>
logSpacedUpdates: Record<string, default>
NoteContextAwareWidget: typeof NoteContextAwareWidget
originEntity: unknown
Entity whose event triggered this execution.
parseDate: (str: string) => Date
protectNote: (
noteId: string,
protect: boolean,
includingSubtree: boolean,
) => Promise<void>
- noteId: string
- protect: boolean
true to protect note, false to unprotect
- includingSubtree: boolean
protectSubTree: (
noteId: string,
protect: boolean,
includingSubtree: boolean,
) => Promise<void>
- noteId: string
- protect: boolean
true to protect subtree, false to unprotect
- includingSubtree: boolean
randomString: (len: number) => string
Return randomly generated string of given length. This random string generation is NOT cryptographically secure.
- len: number
random string
RightPanelWidget: typeof RightPanelWidget
setupElementTooltip: ($el: JQuery<HTMLElement>) => void
- $el: JQuery\<HTMLElement\>
jquery object on which to set up the tooltip
showConfirmDialog: (message: string) => Promise<unknown>
Show confirm dialog to the user.
- message: string
promise resolving to true if the user confirmed
showError: (message: string, delay?: number) => void
Show an error toast message to the user.
showInfoDialog: (message: string) => Promise<unknown>
Show an info dialog to the user.
showMessage: (message: string, delay?: number) => void
Show an info toast message to the user.
showPromptDialog: (props: PromptDialogOptions) => Promise<null | string>
Show prompt dialog to the user.
- props: [PromptDialogOptions](Frontend_Script_API._internal_.PromptDialogOptions.html)
promise resolving to the answer provided by the user
startNote: FNote
Note where the script started executing, i.e., the (event) entrypoint of the current script execution.
triggerCommand: <K extends keyof CommandMappings>(
name: K,
_data?: CommandMappings[K],
) => undefined | null | Promise<unknown>
Trigger command. This is a very low-level API which should be avoided if possible.
triggerEvent: <K extends EventNames>(
name: K,
data: EventData<K>,
) => undefined | null | Promise<unknown>
Trigger event. This is a very low-level API which should be avoided if possible.
waitUntilSynced: () => Promise<void>
Trilium runs in a backend and frontend process, when something is changed on the backend from a script, frontend will get asynchronously synchronized.
This method returns a promise which resolves once all the backend -> frontend synchronization is finished. Typical use case is when a new note has been created, we should wait until it is synced into frontend and only then activate it.
activateNewNote(notePath: string): Promise<void>
Activates newly created note. Compared to this.activateNote() also makes sure that frontend has been fully synced.
(or noteId)
activateNote(notePath: string): Promise<void>
Activates note in the tree and in the note detail.
(or noteId)
addButtonToToolbar(opts: AddToToolbarOpts): void
Adds a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.
you can now create/modify launchers in the top-left Menu -> Configure Launchbar for special needs there's also backend API's createOrUpdateLauncher()
addTextToActiveContextEditor(text: string): void
Adds given text to the editor cursor
this must be clear text, HTML is not supported.
getActiveContext(): NoteContext
returns active context (split)
getActiveContextCodeEditor(): Promise<unknown>
See https://codemirror.net/doc/manual.html#api
instance of CodeMirror
getActiveContextNote(): FNote
active note (loaded into center pane)
getActiveContextNotePath(): null | string
returns a note path of active note or null if there isn't active note
getActiveContextTextEditor(): Promise<unknown>
See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for documentation on the returned instance.
instance of CKEditor
getActiveMainContext(): NoteContext
returns active main context (first split in a tab, represents the tab as a whole)
getActiveNoteDetailWidget(): Promise<default>
Get access to the widget handling note detail. Methods like getWidgetType() and getTypeWidget() to get to the implementation of actual widget type.
getComponentByEl(el: HTMLElement): default
Returns component which owns the given DOM element (the nearest parent component in DOM tree)
DOM element
getInstanceName(): string
Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.
getMainNoteContexts(): NoteContext[]
returns all main contexts representing tabs
getNote(noteId: string): Promise<null | FNote>
Returns note by given noteId. If note is missing from the cache, it's loaded.
getNoteContexts(): NoteContext[]
returns all note contexts (splits) in all tabs
getNotes(noteIds: string[], silentNotFoundError?: boolean): Promise<FNote[]>
Returns list of notes. If note is missing from the cache, it's loaded.
This is often used to bulk-fill the cache with notes which would have to be picked one by one otherwise (by e.g. createLink())
OptionalsilentNotFoundError: booleandon't report error if the note is not found
log(message: string): void
Log given message to the log pane in UI
openSplitWithNote(notePath: string, activate: boolean): Promise<void>
Open a note in a new split.
(or noteId)
set to true to activate the new split, false to stay on the current split
openTabWithNote(notePath: string, activate: boolean): Promise<void>
Open a note in a new tab.
(or noteId)
set to true to activate the new tab, false to stay on the current tab
refreshIncludedNote(includedNoteId: string): void
This will refresh all currently opened notes which have included note specified in the parameter
noteId of the included note
reloadNotes(noteIds: string[]): Promise<void>
Update frontend tree (note) cache from the backend.
runAsyncOnBackendWithManualTransactionHandling(
func: Func,
params: unknown[],
): unknown
Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. This function is meant for advanced needs where an async function is necessary. In this case, the automatic request-scoped transaction management is not applied, and you need to manually define transaction via api.transactional().
If you have a synchronous function, please use api.runOnBackend().
(synchronous) function to be executed on the backend
list of parameters to the anonymous function to be sent to backend
return value of the executed function on the backend
runOnBackend(func: Func, params: unknown[]): unknown
Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. Please make sure that the supplied function is synchronous. Only sync functions will work correctly with transaction management. If you really know what you're doing, you can call api.runAsyncOnBackendWithManualTransactionHandling()
(synchronous) function to be executed on the backend
list of parameters to the anonymous function to be sent to backend
return value of the executed function on the backend
searchForNote(searchString: string): Promise<null | FNote>
This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See full documentation for all options at: https://triliumnext.github.io/Docs/Wiki/search.html
searchForNotes(searchString: string): Promise<FNote[]>
This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See full documentation for all options at: https://triliumnext.github.io/Docs/Wiki/search.html
setHoistedNoteId(noteId: string): void
Hoist note in the current tab. See https://triliumnext.github.io/Docs/Wiki/note-hoisting.html
set hoisted note. 'root' will effectively unhoist
Member Visibility
ThemeOSLightDark
Properties $containerBasicWidgetbindGlobalShortcutcreateLinkcreateNoteLinkcurrentNotedayjsformatDateISOformatNoteSizeformatSizegetDayNotegetMonthNotegetQuarterNotegetTodayNotegetWeekFirstDayNotegetWeekNotegetYearNotelogMessageslogSpacedUpdatesNoteContextAwareWidgetoriginEntityparseDateprotectNoteprotectSubTreerandomStringRightPanelWidgetsetupElementTooltipshowConfirmDialogshowErrorshowInfoDialogshowMessageshowPromptDialogstartNotetriggerCommandtriggerEventwaitUntilSynced Methods activateNewNoteactivateNoteaddButtonToToolbaraddTextToActiveContextEditorgetActiveContextgetActiveContextCodeEditorgetActiveContextNotegetActiveContextNotePathgetActiveContextTextEditorgetActiveMainContextgetActiveNoteDetailWidgetgetComponentByElgetInstanceNamegetMainNoteContextsgetNotegetNoteContextsgetNoteslogopenSplitWithNoteopenTabWithNoterefreshIncludedNotereloadNotesrunAsyncOnBackendWithManualTransactionHandlingrunOnBackendsearchForNotesearchForNotessetHoistedNoteId