We are currently planning to migrate to a different platform for the forum. We will announce this fact both here and on Twitter, once we have settled on a solution.

auto generate a header

Is it possible to auto generate a header with template when open a new file


  • I don't think Zettlr has such a feature, but it is not hard to implement it with additional tools. I use this autohotkey script:

    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
    #SingleInstance force  ; Ensures that only the last executed instance of script is running
    DetectHiddenWindows, On
      FormatTime, CurrentDateTime,, yyyy-MM-dd HH:mm
      Send, ---{shift down}{enter}{shift up}
      Send, id: %A_Now% `ncontent-tags: `ntype-tags: `ncreated: %CurrentDateTime%`n
      Send, ---{shift down}{enter}{shift up}
      Send, {enter}{enter}{#}{#} Source{enter}

    To use it, you should:

    id: 20201113105510 
    created: 2020-11-13 10:55
    ## Source

    I admit, I am not very good at writing AHK scripts, so there are probably more elegant ways to do this. You can modify the script to make it generate whatever you want your template to look like.

    If autohotkey is too much trouble, there are a lot of text expanders out there (for example https://espanso.org/) that can do basically the same thing without scripting (not sure they can auto-generate an ID from the current data-time though).

  • I'm finding espanso works very well for this purpose. I'd recommend it over AHK because it's FOSS, platform independent, and portable.

    Although it does not automatically add a template or assign a hot key, you can define text strings ("triggers") that do the same thing. For example, suppose you define three templates: ":menu", ":lit", and ":perm". If you open a new note and enter ":menu", you can generate a list of all your templates. If you then issue ^z to undo your changes to the blank document and now, instead enter ":lit", you can generate a template for a "literature" note. Similarly, entering ":perm" can generate a general template for a permanent note.

    You can define application-specific and system-wide triggers.

    In fact, espanso has some advanced features that can make the process even better. For example, you can associate a trigger with a form. So, for instance, you can associate ":lit" with a form that pops up and asks for an author & title; when you fill in the form and close it, these fields are assigned to variables. Then, as espanso expands the :lit note, it can reuse them. For example, it can automatically enter the "title" in the YAML frontmatter to title the note AND later on in the note where you might store bibliographic metadata for the source. Espanso also can invoke shell scripts to feed it text, create dropdown lists, and more.

    It's also being actively maintained.

Sign In or Register to comment.