New draft in current workspace

There is a menu option to do this. Well this is a menu option to create a draft in a workspace, but my intended use case is that when you’re in a workspace you should be able to perform a keyboard shortcut and create a new draft in the current workspace (or default if you don’t have a named workspace selected).

I have the script written and it works more or less how I want. I noticed though that when using the Draft constructor to create the draft object, it doesn’t seem to create the draft unless you give it content. Is that intended behavior or did I stumble upon something strange?

Here is my script:

/// a drafts script that looks for the current workspace 
/// and adds a new draft with the associated tags
/// then opens that draft in the editor

const currentWorkspace = app.currentWorkspace;
const workspaceName =
const tags = currentWorkspace.tagFilter.split(",");

let d = new Draft();
tags.forEach(tag => d.addTag(tag));
d.content = `# New Draft in Current Workspace: ${workspaceName}\n-`;


I have content filled because I can’t make a draft without it, but wondering if there is a way around this.

Also note that technically this doesn’t create it in the workspace but instead creates a draft using the same tags as the workspace. This just happens to be how I set up my workspace so there might be other things I’m missing, but I’m not planning to share this with the world per se. Unless someone really wants it.

1 Like

A new draft is not saved until it has content. That is intentional, to avoid an inbox cluttered with blank drafts.

Is there a reason you want to force it be be saved before you have actually put any text in it? Your script can just skip the update() call and load your new draft in the editor. If you actually start typing in it, it will be saved by the editor. If not, it will just be abandoned.

If you really do want the blank draft saved to matter what, you could put some text in it like your example, call update(), then reset the content to blank and call update() again. Once a draft has been saved with content, it will not be deleted even if it empty.

@agiletortoise This is exactly what I was looking for! Thanks so much. And thanks for making an amazing app.

One last thing, do you make your typescript definition files available anywhere so that I could plug them into something like a nodejs project and get the typescript language server to help with autocompletion in a proper IDE? I imagine something like syntax highlighting in the script editor is a big ask, but with those *.d.ts files I’d be able to leverage something like Nova or VSCode to handle that for me.

The repo is linked from the home page of the reference site. A complete def file is generated already in the build process as well.

You might find this thread useful.

@sylumer Thanks so much. That’s really handy. I’m wondering what @agiletortoise would think of adding the .d.ts file to DefinitelyTyped so users could pull that down as part of a node project. Perhaps that’s already in the thread, but I’ll read through it more tonight.