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.

Creating linked Zettel with Autohotkey

The gif explains what this is all about.

I like to create Zettel and have link straight to it in some parent Zettel. This is small script to make creating child Zettel easier.

Autohotkey is program to make scripts:
https://www.autohotkey.com/

This is for those, who already know how to use Autohotkey.

How to use script:
1. Click where you want your link
2. Press CTRL + SHIFT + B

Here is the Autohotkey script. Remember to change the folder "zettlrFolder".
Code between `` characters.

`
#IfWinActive ahk_exe Zettlr.exe

;Shortcut, wait CTRL and SHIFT to be lifted up before doing anything.
^+b::
KeyWait, Ctrl
KeyWait, Shift

;Create date time string
FormatTime, CurrentDateTime,, yyyyMMddHHmmss
fileToBeCreatedName=%CurrentDateTime%

;Paste date time string to current text cursor position
clipboard= [[%fileToBeCreatedName%]]
Send {Ctrl down}{v}{Ctrl up}

;Copy current file name to clipboard using Zettlr GUI and shortcut
Send {Ctrl down}{r}{Ctrl up}
Send {Ctrl down}{c}{Ctrl up}
Send {Esc}

;Clipboard to variable
currentFileName= %clipboard%

;Take prefix .md away from currentFileName string
StringReplace,currentFileName,currentFileName,.md,, All

;Define folder. CHANGE THIS TO YOUR ZETTLR WORKING FOLDER WHERE YOU WANT NEW FILE TO BE CREATED!
zettlrFolder=C:\YOUR_FOLDER_PATH

;Write to new file. First line is link to currentFileName. After that, two newlines.
FileAppend, [[%currentFileName%]]`n`n, %zettlrFolder%\%fileToBeCreatedName%.md
`

This is kind of proof of concept, but someone might find this useful.

Comments

  • Thank you!

  • edited March 19

    I improved the script a little.

    How it works now:

    1. Select text which you want to be the title of a new Zettel.
    2. Press CTRL + SHIFT + B
    3. Voila

    See the video attached.

    Script between ''-marks.

    '
    #IfWinActive ahk_exe Zettlr.exe

    ;Shortcut
    ^+b::
    KeyWait, Ctrl
    KeyWait, Shift

    ;Copy current text selection to clipboard
    Send {Ctrl down}{c}{Ctrl up}

    ;Clipboard to variable
    titleText=%clipboard%

    ;Create date time string
    FormatTime, CurrentDateTime,, yyyyMMddHHmmss
    fileToBeCreatedName=%CurrentDateTime%

    ;Paste date time string + titletext to current text cursor position
    clipboard= [[%fileToBeCreatedName%]] %titleText%
    Send {Ctrl down}{v}{Ctrl up}

    ;Copy current file name to clipboard using Zettlr GUI and shortcut
    Send {Ctrl down}{r}{Ctrl up}
    Send {Ctrl down}{c}{Ctrl up}
    Send {Esc}

    ;Clipboard to variable
    currentFileName= %clipboard%

    ;Take prefix .md away from currentFileName string
    StringReplace,currentFileName,currentFileName,.md,, All

    ;Define folder. CHANGE THIS TO YOUR ZETTLR WORKING FOLDER WHERE YOU WANT NEW FILE TO BE CREATED!
    zettlrFolder=C:\YOUR_FOLDER_PATH

    ;Write to new file. First line is link to currentFileName. After that, two newlines.
    FileAppend, [[%currentFileName%]]`n`n# %titleText%`n`n, %zettlrFolder%\%fileToBeCreatedName%.md

    '

Sign In or Register to comment.