Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Create a new note in Inbox using template #14

Closed
baseliners opened this issue Mar 23, 2022 · 16 comments
Closed

Feature request: Create a new note in Inbox using template #14

baseliners opened this issue Mar 23, 2022 · 16 comments
Assignees
Labels
enhancement New feature or request

Comments

@baseliners
Copy link

Would be great to have a command to create a new note in Inbox that uses the template assigned to new notes in Inbox via the templater plugin (eg I have a template for any new note in Inbox that creates a prefix for the filename with today's date in almost-Zettel format). Thx for this plugin!

@marcjulianschwarz
Copy link
Collaborator

So you want to be able to have a template for the filename and content of a note?

How I understand the feature request

Lets say I create a new command Create Note from Template. How should that command work?
I haven't used the Templater Plugin yet but I guess you will have a dedicated folder with template files in it. You could now enter this path in the preferences of the Create Note from Template command. Activating it will show a searchable list with all the templates from the folder that you entered in the preferences. After selecting one it will open the normal Create Note form where filename and content will be prefilled with the values from the template.

Now as I can tell from what you wrote, the Templater Plugin supports some placeholders (e.g. Zettelkasten/date) which will be replaced when creating a new note from a template. To have this functionality in Raycast I would need to implement these placeholders too.

Some questions

Could you tell me which placeholders have to be added and what syntax is being used to mark placeholders? (e.g. {{date}})

Do you think this would come close to the templater experience? Anything to add/remove?

Thank you for the feature request!

@marcjulianschwarz marcjulianschwarz added the enhancement New feature or request label Mar 23, 2022
@marcjulianschwarz marcjulianschwarz self-assigned this Mar 23, 2022
@marcjulianschwarz
Copy link
Collaborator

Hi @baseliners,

any thoughts on this?

@baseliners
Copy link
Author

Hi @marcjulianschwarz - the way I was thinking about this is simpler (I think). i.e. your raycast plugin would invoke whatever mechanism Obisidian is using to create a new note using a Templater template. Not sure if the advanced URI plugin already handles templates, but if yes, it might be as simple as invoking a new note creation URI for a note in a certain folder, and if that folder has a template associated with it in Templater, that template gets used.

Personally, I'd be OK losing the form functionality that you currently have and have the plugin just drop me directly into Obsidian. If you wanted to parameterize, I'd parameterize the folder where a new note is being created, and allow for keyboard shortcuts to be assigned to each folder. i.e. I can assign a keyboard shortcut to create a note in Inbox, and another shortcut to create a note in folder XYZ, etc. This would provide a lot of flexibility and you wouldn't have to duplicate the templater functionality in your plugin. Thx!

@marcjulianschwarz
Copy link
Collaborator

Hi @baseliners,

thank you for the clarifications. Now I understand how the Templater plugin works, didn't know about the folder-template-association.

In the Create Note preference section you can now enter a list of folders.

Bildschirmfoto 2022-04-23 um 12 03 43

These folders will show up as actions in the command. Triggering them will add a new empty file in the corresponding folder. You can still override the path using the form or you could add a filename with the form. I think the notes content will be replaced with the template.

Bildschirmfoto 2022-04-23 um 12 04 03

Open for feedback :)

@marcjulianschwarz
Copy link
Collaborator

Right now the shortcut for every action will be created automatically (counting from 0 to 9). I might need to change this behavior as some of these keyboard combinations are already in use by the OS.

@baseliners
Copy link
Author

This sounds great! How can I try it out?

@marcjulianschwarz
Copy link
Collaborator

You could download/clone this repository, then navigate to the folder and run npm install and npm run dev. The extension should then be visible in Raycast.

@marcjulianschwarz
Copy link
Collaborator

@baseliners let me know when you were able to test it.

@baseliners
Copy link
Author

Thanks. I was able to install and run it, but when I trigger the action for the Inbox folder, it tries to create a note with the filename Untitled.md instead of the filename that should be generated via the Templater template. Here's what my template looks like for the Inbox folder (i.e. the following line is what the template file associated w/ Inbox contains):

<% tp.file.rename(tp.date.now("YYYY-MM-DD") + " ") %>

So in Obsidian, if I create a new note (I have Inbox as the default location for new notes), the filename generated would be something like 2022-04-23<my_text>.md (I add text manually after the date so it ends up making the filename unique).

I suppose the extension is bypassing the Templater somehow. Wonder if there's a way to have Templater still trigger even if the note creation is triggered by the Raycast extension?

@marcjulianschwarz
Copy link
Collaborator

marcjulianschwarz commented Apr 24, 2022

Templater will trigger. I tried some of the examples from Templaters website and they worked.
I tested your template too and it worked fine for me. It renamed the Untitled.md file.

Maybe the plugin isn't enabled or the template hasn't been selected in Templaters settings?
Do you see any errors?

@marcjulianschwarz
Copy link
Collaborator

This shows it working:

2022-04-24.23-54-47.mp4

As you can see Obsidian will throw an error that the file doesn't exist because it got renamed (Raycast is trying to open the old file name, this can be disabled in the extensions settings).

@baseliners
Copy link
Author

OK great, figured out the issue. I already had a file named Untitled.md in my Inbox so it was preserving that file. May be worth choosing another default name for the temp file?

Also, noticed that if I use the Command+Shift+return shortcut to create the note, it does create the file but does not drop me into the note. If I hit Command-K and then select the action for Inbox, it does drop me into the note that was just created. Not sure if this is intended behavior? I have the checkbox checked for "Open note on Creation" so was expecting the note to be opened via the keyboard shortcut as well.

Btw, is there a way to set a global shortcut for the action to create a new note in Inbox? I set a global shortcut to "Create Note" but would be nice to have a shortcut for creating a note in a specific folder as well.. but maybe this is something that Raycast needs to support?

@marcjulianschwarz
Copy link
Collaborator

Which default name would you suggest?

Can't reproduce this behavior. Both the shortcut and manually selecting the action from the list works for me.

I don't think there is a way to set global shortcuts for actions. The only way this would work is to create commands for each folder. However I don't think that this would comply with Raycasts guidelines for extensions. For "non-tech people" this could be quite confusing.

@marcjulianschwarz
Copy link
Collaborator

@baseliners any suggestions?

I can add a preference where you can choose the default note name.

@marcjulianschwarz
Copy link
Collaborator

Hi @baseliners,

I just pushed a new version. You can now specify a default note name for the Create Note command which is being used when the name field is left empty.

@marcjulianschwarz
Copy link
Collaborator

Hi @baseliners,
version 1.5 has been released and it includes your feature request.
Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants