# Interface Api

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;
}

- Defined in src/public/app/services/frontend_script_api.ts:62

##### Index

### Properties

$container
BasicWidget
bindGlobalShortcut
createLink
createNoteLink
currentNote
dayjs
formatDateISO
formatNoteSize
formatSize
getDayNote
getMonthNote
getQuarterNote
getTodayNote
getWeekFirstDayNote
getWeekNote
getYearNote
logMessages
logSpacedUpdates
NoteContextAwareWidget
originEntity
parseDate
protectNote
protectSubTree
randomString
RightPanelWidget
setupElementTooltip
showConfirmDialog
showError
showInfoDialog
showMessage
showPromptDialog
startNote
triggerCommand
triggerEvent
waitUntilSynced

### Methods

activateNewNote
activateNote
addButtonToToolbar
addTextToActiveContextEditor
getActiveContext
getActiveContextCodeEditor
getActiveContextNote
getActiveContextNotePath
getActiveContextTextEditor
getActiveMainContext
getActiveNoteDetailWidget
getComponentByEl
getInstanceName
getMainNoteContexts
getNote
getNoteContexts
getNotes
log
openSplitWithNote
openTabWithNote
refreshIncludedNote
reloadNotes
runAsyncOnBackendWithManualTransactionHandling
runOnBackend
searchForNote
searchForNotes
setHoistedNoteId

## Properties

### $container

$container: null | JQuery<HTMLElement>

Container of all the rendered script content

- Defined in src/public/app/services/frontend_script_api.ts:66

### BasicWidget

BasicWidget: typeof BasicWidget

- Defined in src/public/app/services/frontend_script_api.ts:92

### bindGlobalShortcut

bindGlobalShortcut: (
keyboardShortcut: string,
handler: null | Handler ,
namespace?: null | string,
) => void

#### Type declaration

- - (
    keyboardShortcut: string,
    handler: null | Handler ,
    namespace?: null | string,
    ): void

  - #### Parameters

    - keyboardShortcut: string

      e.g. "ctrl+shift+a"

    - handler: null | Handler
    - 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.

    #### Returns void

- Defined in src/public/app/services/frontend_script_api.ts:412

### createLink

createLink: (
notePath: undefined | string,
options?: CreateLinkOptions ,
) => Promise<JQuery<HTMLElement>>

Create a note link (jQuery object) for given note.

#### Type declaration

- - (
    notePath: undefined | string,
    options?: CreateLinkOptions ,
    ): Promise<JQuery<HTMLElement>>

  - #### Parameters

    - notePath: undefined | string

      (or noteId)

    - options: CreateLinkOptions = {}

    #### Returns Promise<JQuery<HTMLElement>>

    - jQuery element with the link (wrapped in )

- Defined in src/public/app/services/frontend_script_api.ts:263

### createNoteLink

createNoteLink: (
notePath: undefined | string,
options?: CreateLinkOptions ,
) => Promise<JQuery<HTMLElement>>

#### Deprecated

- use api.createLink() instead

- Defined in src/public/app/services/frontend_script_api.ts:266

### currentNote

currentNote: FNote

Note where the script is currently executing, i.e. the note where the currently executing source code is written.

- Defined in src/public/app/services/frontend_script_api.ts:76

### dayjs

dayjs: __module

day.js library for date manipulation. See https://day.js.org for documentation

#### See

https://day.js.org

- Defined in src/public/app/services/frontend_script_api.ts:88

### formatDateISO

formatDateISO: (date: Date) => string

#### Type declaration

- - (date: Date): string

  - this is producing local time! *

    #### Parameters

    - date: Date

    #### Returns string

#### Returns

date in YYYY-MM-DD format

- Defined in src/public/app/services/frontend_script_api.ts:209

### formatNoteSize

formatNoteSize: (size: number) => string

#### Type declaration

- - (size: number): string

  - #### Parameters

    - size: number

      in bytes

    #### Returns string

    formatted string

#### Deprecated

- use api.formatSize()

- Defined in src/public/app/services/frontend_script_api.ts:450

### formatSize

formatSize: (size: number) => string

#### Type declaration

- - (size: number): string

  - #### Parameters

    - size: number

      in bytes

    #### Returns string

    formatted string

- Defined in src/public/app/services/frontend_script_api.ts:443

### getDayNote

getDayNote: (date: string) => Promise<null | FNote >

Returns day note for a given date. If it doesn't exist, it is automatically created.

#### Type declaration

- - (date: string): Promise<null | FNote >

  - #### Parameters

    - date: string

      e.g. "2019-04-29"

    #### Returns Promise<null | FNote >

- Defined in src/public/app/services/frontend_script_api.ts:359

### getMonthNote

getMonthNote: (month: string) => Promise<null | FNote >

Returns month-note. If it doesn't exist, it is automatically created.

#### Type declaration

- - (month: string): Promise<null | FNote >

  - #### Parameters

    - month: string

      e.g. "2019-04"

    #### Returns Promise<null | FNote >

- Defined in src/public/app/services/frontend_script_api.ts:381

### getQuarterNote

getQuarterNote: (quarter: string) => Promise<null | FNote >

Returns quarter note for given date. If such a note doesn't exist, it is automatically created.

- Defined in src/public/app/services/frontend_script_api.ts:389

### getTodayNote

getTodayNote: () => Promise<null | FNote >

Returns date-note for today. If it doesn't exist, it is automatically created.

- Defined in src/public/app/services/frontend_script_api.ts:352

### getWeekFirstDayNote

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.

#### Type declaration

- - (date: string): Promise<null | FNote >

  - #### Parameters

    - date: string

      e.g. "2019-04-29"

    #### Returns Promise<null | FNote >

- Defined in src/public/app/services/frontend_script_api.ts:366

### getWeekNote

getWeekNote: (week: string) => Promise<null | FNote >

Returns week note for given date. If such a note doesn't exist, it is automatically created.

- Defined in src/public/app/services/frontend_script_api.ts:374

### getYearNote

getYearNote: (year: string) => Promise<null | FNote >

Returns year-note. If it doesn't exist, it is automatically created.

#### Type declaration

- - (year: string): Promise<null | FNote >

  - #### Parameters

    - year: string

      e.g. "2019"

    #### Returns Promise<null | FNote >

#### Method

- Defined in src/public/app/services/frontend_script_api.ts:398

### logMessages

logMessages: Record <string, string[]>

- Defined in src/public/app/services/frontend_script_api.ts:452

### logSpacedUpdates

logSpacedUpdates: Record <string, default >

- Defined in src/public/app/services/frontend_script_api.ts:453

### NoteContextAwareWidget

NoteContextAwareWidget: typeof NoteContextAwareWidget

- Defined in src/public/app/services/frontend_script_api.ts:91

### originEntity

originEntity: unknown

Entity whose event triggered this execution.

- Defined in src/public/app/services/frontend_script_api.ts:81

### parseDate

parseDate: (str: string) => Date

- Defined in src/public/app/services/frontend_script_api.ts:211

### protectNote

protectNote: (
noteId: string,
protect: boolean,
includingSubtree: boolean,
) => Promise<void>

#### Type declaration

- - (noteId: string, protect: boolean, includingSubtree: boolean): Promise<void>

  - #### Parameters

    - noteId: string
    - protect: boolean

      true to protect note, false to unprotect

    - includingSubtree: boolean

    #### Returns Promise<void>

- Defined in src/public/app/services/frontend_script_api.ts:341

### protectSubTree

protectSubTree: (
noteId: string,
protect: boolean,
includingSubtree: boolean,
) => Promise<void>

#### Type declaration

- - (noteId: string, protect: boolean, includingSubtree: boolean): Promise<void>

  - #### Parameters

    - noteId: string
    - protect: boolean

      true to protect subtree, false to unprotect

    - includingSubtree: boolean

    #### Returns Promise<void>

- Defined in src/public/app/services/frontend_script_api.ts:347

### randomString

randomString: (len: number) => string

Return randomly generated string of given length. This random string generation is NOT cryptographically secure.

#### Type declaration

- - (len: number): string

  - #### Parameters

    - len: number

    #### Returns string

    random string

#### Method

- Defined in src/public/app/services/frontend_script_api.ts:437

### RightPanelWidget

RightPanelWidget: typeof RightPanelWidget

- Defined in src/public/app/services/frontend_script_api.ts:90

### setupElementTooltip

setupElementTooltip: ($el: JQuery<HTMLElement>) => void

#### Type declaration

- - ($el: JQuery<HTMLElement>): void

  - #### Parameters

    - $el: JQuery<HTMLElement>

      jquery object on which to set up the tooltip

    #### Returns void

- Defined in src/public/app/services/frontend_script_api.ts:336

### showConfirmDialog

showConfirmDialog: (message: string) => Promise<unknown>

Show confirm dialog to the user.

#### Type declaration

- - (message: string): Promise<unknown>

  - #### Parameters

    - message: string

    #### Returns Promise<unknown>

    promise resolving to true if the user confirmed

- Defined in src/public/app/services/frontend_script_api.ts:232

### showError

showError: (message: string, delay?: number) => void

Show an error toast message to the user.

- Defined in src/public/app/services/frontend_script_api.ts:221

### showInfoDialog

showInfoDialog: (message: string) => Promise<unknown>

Show an info dialog to the user.

- Defined in src/public/app/services/frontend_script_api.ts:226

### showMessage

showMessage: (message: string, delay?: number) => void

Show an info toast message to the user.

- Defined in src/public/app/services/frontend_script_api.ts:216

### showPromptDialog

showPromptDialog: (props: PromptDialogOptions ) => Promise<null | string>

Show prompt dialog to the user.

#### Type declaration

- - (props: PromptDialogOptions ): Promise<null | string>

  - #### Parameters

    - props: PromptDialogOptions

    #### Returns Promise<null | string>

    promise resolving to the answer provided by the user

- Defined in src/public/app/services/frontend_script_api.ts:239

### startNote

startNote: FNote

Note where the script started executing, i.e., the (event) entrypoint of the current script execution.

- Defined in src/public/app/services/frontend_script_api.ts:71

### triggerCommand

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.

- Defined in src/public/app/services/frontend_script_api.ts:244

### triggerEvent

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.

- Defined in src/public/app/services/frontend_script_api.ts:249

### waitUntilSynced

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.

- Defined in src/public/app/services/frontend_script_api.ts:421

## Methods

### activateNewNote

- activateNewNote(notePath: string): Promise<void>

  Activates newly created note. Compared to this.activateNote() also makes sure that frontend has been fully synced.

  #### Parameters

  - notePath: string

    (or noteId)

  #### Returns Promise<void>

  - Defined in src/public/app/services/frontend_script_api.ts:106

### activateNote

- activateNote(notePath: string): Promise<void>

  Activates note in the tree and in the note detail.

  #### Parameters

  - notePath: string

    (or noteId)

  #### Returns Promise<void>

  - Defined in src/public/app/services/frontend_script_api.ts:99

### addButtonToToolbar

- addButtonToToolbar(opts: AddToToolbarOpts ): void

  Adds a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.

  #### Parameters

  - opts: AddToToolbarOpts

  #### Returns void

  #### Method

  #### Deprecated

  you can now create/modify launchers in the top-left Menu -> Configure Launchbar for special needs there's also backend API's createOrUpdateLauncher()

  - Defined in src/public/app/services/frontend_script_api.ts:132

### addTextToActiveContextEditor

- addTextToActiveContextEditor(text: string): void

  Adds given text to the editor cursor

  #### Parameters

  - text: string

    this must be clear text, HTML is not supported.

  #### Returns void

  - Defined in src/public/app/services/frontend_script_api.ts:273

### getActiveContext

- getActiveContext(): NoteContext

  #### Returns NoteContext

  returns active context (split)

  - Defined in src/public/app/services/frontend_script_api.ts:283

### getActiveContextCodeEditor

- getActiveContextCodeEditor(): Promise<unknown>

  See https://codemirror.net/doc/manual.html#api

  #### Returns Promise<unknown>

  instance of CodeMirror

  #### Method

  - Defined in src/public/app/services/frontend_script_api.ts:313

### getActiveContextNote

- getActiveContextNote(): FNote

  #### Returns FNote

  active note (loaded into center pane)

  - Defined in src/public/app/services/frontend_script_api.ts:278

### getActiveContextNotePath

- getActiveContextNotePath(): null | string

  #### Returns null | string

  returns a note path of active note or null if there isn't active note

  - Defined in src/public/app/services/frontend_script_api.ts:323

### getActiveContextTextEditor

- getActiveContextTextEditor(): Promise<unknown>

  See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for documentation on the returned instance.

  #### Returns Promise<unknown>

  instance of CKEditor

  - Defined in src/public/app/services/frontend_script_api.ts:305

### getActiveMainContext

- getActiveMainContext(): NoteContext

  #### Returns NoteContext

  returns active main context (first split in a tab, represents the tab as a whole)

  - Defined in src/public/app/services/frontend_script_api.ts:288

### getActiveNoteDetailWidget

- 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.

  #### Returns Promise< default >

  - Defined in src/public/app/services/frontend_script_api.ts:319

### getComponentByEl

- getComponentByEl(el: HTMLElement): default

  Returns component which owns the given DOM element (the nearest parent component in DOM tree)

  #### Parameters

  - el: HTMLElement

    DOM element

  #### Returns default

  #### Method

  - Defined in src/public/app/services/frontend_script_api.ts:331

### getInstanceName

- 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.

  #### Returns string

  - Defined in src/public/app/services/frontend_script_api.ts:204

### getMainNoteContexts

- getMainNoteContexts(): NoteContext []

  #### Returns NoteContext []

  returns all main contexts representing tabs

  - Defined in src/public/app/services/frontend_script_api.ts:298

### getNote

- getNote(noteId: string): Promise<null | FNote >

  Returns note by given noteId. If note is missing from the cache, it's loaded.

  #### Parameters

  - noteId: string

  #### Returns Promise<null | FNote >

  - Defined in src/public/app/services/frontend_script_api.ts:183

### getNoteContexts

- getNoteContexts(): NoteContext []

  #### Returns NoteContext []

  returns all note contexts (splits) in all tabs

  - Defined in src/public/app/services/frontend_script_api.ts:293

### getNotes

- 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())

  #### Parameters

  - noteIds: string[]
  - `Optional` silentNotFoundError: boolean

    don't report error if the note is not found

  #### Returns Promise< FNote []>

  - Defined in src/public/app/services/frontend_script_api.ts:193

### log

- log(message: string): void

  Log given message to the log pane in UI

  #### Parameters

  - message: string

  #### Returns void

  - Defined in src/public/app/services/frontend_script_api.ts:458

### openSplitWithNote

- openSplitWithNote(notePath: string, activate: boolean): Promise<void>

  Open a note in a new split.

  #### Parameters

  - notePath: string

    (or noteId)

  - activate: boolean

    set to true to activate the new split, false to stay on the current split

  #### Returns Promise<void>

  - Defined in src/public/app/services/frontend_script_api.ts:123

### openTabWithNote

- openTabWithNote(notePath: string, activate: boolean): Promise<void>

  Open a note in a new tab.

  #### Parameters

  - notePath: string

    (or noteId)

  - activate: boolean

    set to true to activate the new tab, false to stay on the current tab

  #### Returns Promise<void>

  #### Method

  - Defined in src/public/app/services/frontend_script_api.ts:115

### refreshIncludedNote

- refreshIncludedNote(includedNoteId: string): void

  This will refresh all currently opened notes which have included note specified in the parameter

  #### Parameters

  - includedNoteId: string

    noteId of the included note

  #### Returns void

  - Defined in src/public/app/services/frontend_script_api.ts:428

### reloadNotes

- reloadNotes(noteIds: string[]): Promise<void>

  Update frontend tree (note) cache from the backend.

  #### Parameters

  - noteIds: string[]

  #### Returns Promise<void>

  - Defined in src/public/app/services/frontend_script_api.ts:198

### runAsyncOnBackendWithManualTransactionHandling

- 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().

  #### Parameters

  - func: Func

    (synchronous) function to be executed on the backend

  - params: unknown[]

    list of parameters to the anonymous function to be sent to backend

  #### Returns unknown

  return value of the executed function on the backend

  #### Method

  - Defined in src/public/app/services/frontend_script_api.ts:166

### runOnBackend

- 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()

  #### Parameters

  - func: Func

    (synchronous) function to be executed on the backend

  - params: unknown[]

    list of parameters to the anonymous function to be sent to backend

  #### Returns unknown

  return value of the executed function on the backend

  #### Method

  - Defined in src/public/app/services/frontend_script_api.ts:150

### searchForNote

- 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

  #### Parameters

  - searchString: string

  #### Returns Promise<null | FNote >

  - Defined in src/public/app/services/frontend_script_api.ts:178

### searchForNotes

- 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

  #### Parameters

  - searchString: string

  #### Returns Promise< FNote []>

  - Defined in src/public/app/services/frontend_script_api.ts:172

### setHoistedNoteId

- setHoistedNoteId(noteId: string): void

  Hoist note in the current tab. See https://triliumnext.github.io/Docs/Wiki/note-hoisting.html

  #### Parameters

  - noteId: string

    set hoisted note. 'root' will effectively unhoist

  #### Returns void

  - Defined in src/public/app/services/frontend_script_api.ts:405