Zettelkasten Forum

Quick insertion of links to other Zettels with type-ahead search (using Keyboard Maestro)

The suberb Keyboard Maestro offers great possibilities to extend The Archive.

Use case: Wouldn't it be nice to insert a link to another Zettel into The Archive by simply selecting it from a list. Think of this as a sort of omnibar-functionality for inserting Zettel links.

This is rather easy to implement with Keyboard Maestro. Set up a macro like this:

A short rundown of the macro:

  1. The first action saves the current list of all file names in your Zettelkasten to a variable. Of course you should change the path in the action to match your archive location (surround the path with "if it contains spaces, e.g. "/path to/my zettelkasten folder"
  2. This steps summons a search bar for all your Zettels
  3. This action pastes the filename and surrounds it with [[]]
  4. (optional step) Cleans up the clipboard history

Don't forget to give the macro a convenient keyboard shortcut and you are set for super fast link insertion. This image gives an idea how this looks:

Keyboard Maestro users can download the macro file for easy import into their macro library.

Summary: The Archive and Keyboard Maestro: a match made in heaven.



  • Awesome, thanks for this!

  • edited March 2018

    Hi Roland,
    Cool macro. Is there an easy way to exclude the file extension from being included in the link name (TA tries to create a new note with the file name+extension as the "new" name when I click on the link)? Unfortunately I am a newbie with KM, so I have no idea how to begin implementing such a cleanup in your macro...


  • edited March 2018

    Hi, Eric,

    ups. I was sure, it worked yesterday :-) But you are right on the "extension problem". Fortunately, this is easy to fix with an additional search-replace step in the macro. Enter the following step at position 3 (after the "Prompt With List" step):

    Basically, the additional step removes the extension from the file name in the variable using the regular expression \.[^.]+?\Z (leave the replace field empty). This version works on my machine, even if the Filename contains periods before the extension (like some. strange. file. name.txt)

    I also updated the linked macro file to this version.


  • Hi Roland,
    Thanks for the quick fix. It works like a charm on my machine as well. Thanks for sharing!

  • That is amazing. Thanks for sharing and I look forward to lots of amazing KM macros!

    This is Me

  • Great work!

    I didn't like the file extensions being shown in the file list, so I modified the macro to first strip the file extensions before showing the list (using a "for each line in variable" block). With my 230 notes, this however results in a delay of about two seconds before the list window is shown, which is slightly irritating.

    Now I am trying to figure out whether I want to try to create a better performing version of the macro, or whether I should just learn to love the file extensions. :wink:

    Anyway, thanks again for a very useful macro!

    If you like The Archive's "PrettyFunctional (Basic)" theme, consider upgrading to the "PrettyFunctional (Regular)" theme.

  • I've now figured out a much faster way to get a file list without file extensions: Simply replace ls -t in the original macro with ls -t | sed -e 's/.txt//'. Then you can also delete the "Search and Replace Variable" action.

    If you like The Archive's "PrettyFunctional (Basic)" theme, consider upgrading to the "PrettyFunctional (Regular)" theme.

  • Thanks @Basil for the improved version, it's working like a charm and @kaidoh for the original script. Very useful.

  • Hi Basil,
    thanks for improving on the macro. You're right, the command line is faster than Keyboard Maestros implementation on almost every occasion. The downside: it is almost ever a lot harder to figure out the right commands and arguments.

    Your version works fine if you only have .txt files. If you use files with other extensions (.md, .markdown, .taskpaper, .whatnot ...) you could try this slightly adapted version:

    cd ~/Dropbox/zettelkasten
    ls -t | sed -e 's/.[^.]*$//'

    I changed the original macro to include Basil's idea. Download it here.


  • Great work! We'll totally post this on the blog.

    Author at Zettelkasten.de • https://christiantietze.de/

  • Late to the party!
    Thanks, @kaidoh for work on these scripts and the intro to Keyboard Maestro.
    I have about 50 notes so far, just a beginner. When I use this script in KM I get the list of note links I can select from and it works. I'd like to sort the list of notes but can't figure a way. I seem to always get a sorting by name. Putting oldest first. I'd like to switch that to newest first so I don't have to scroll so much. Even when using

    ls -Ur | sed -e 's/.[^.]*$//'

    The list I get using Terminal is sorted differently for the list populated to tmp in KM.

    Any tips would be helpful. Thanks

    Will Simpson

  • edited February 26

    Another great KM-macro, thanks!
    Is there an easy way to have just the Zettel-ID part copied in the note after choosing one in the search window instead of the whole note title, so [[201901212335]] instead of [[201901212335 Example Note]]? I always link to other notes just using the Zettel-ID in brackets.

  • @Vinho YES! This is the Keyboard Maestro macro that I use for just this purpose. Easy peasy!

    Insert Note Link

    Download, import, change the directory and when creating a note just type [[ and typeahead search for the link, hit enter and continue. A link of the type [[201901212335]] will be inserted.

    This is not all my creation. Credit to @kaidoh for the kernel that inspired this and to @sfast for his insistence that links just be a UID so the titles are free to change without a loss in connectivity.

    Will Simpson

  • That's great Will, works perfectly! And suddenly I enjoy using The Archive soooo much more!!

  • Ok guys I finally went for it and bought Keyboard Maestro. I'm posting this on this thread because the functionality that y'all built here was the primary reason I did so, but I'm enjoying looking at the other things I can do with it.

    I just thought I should announce it because I complained so much about it :)

Sign In or Register to comment.