How to get current file name in space script?

I’ve read the documentation here, yet it seems to me not clear how can I implement a script based on information of current filename. For example a command to go to the previous daily notes can be adapted from the following script if we can access the current filename.

silverbullet.registerCommand({ name: 'Notes: Yesterday' }, async () => {
    // Get today's date
    const today = Temporal.Now.plainDateISO();
    // Subtract one day to get yesterday's date
    const yesterday = today.subtract({ days: 1 }).toString();
  
    // Navigate to the note from yesterday
    syscall('editor.navigate', `Notes/${yesterday}`)
})

await syscall("editor.getCurrentPage") will give you the currently open page.

Thanks! @zef, I searched the documentation several times, yet the editor namespace was not included in the documentation. I wonder if there is a way to find all the available syscall commands??

Yes, this is a known issue: Space Script documentation does not list all syscalls · Issue #839 · silverbulletmd/silverbullet · GitHub

What I can offer until that’s resolved is this: silverbullet/web/syscalls at main · silverbulletmd/silverbullet · GitHub

This contains the client-specific (implementations of) syscalls.

That is good! I can get more information from the source code, about the usage as well. Thanks for the guidance!

1 Like