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.

Enjoy,
Roland

Comments

  • 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...

    Thanks,
    Eric

  • 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.

    Roland

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

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

    -apoc527
    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.

    Roland

  • 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
    My zettelkasten is for my ideas, not the ideas of others. I don’t want to waste my time tinkering with my ZK; I’d rather dive into the work itself. My peak cognition is behind me. One day soon, I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • edited February 2019

    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 @Sascha for his insistence that links just be a UID so the titles are free to change without a loss in connectivity.

    Will Simpson
    My zettelkasten is for my ideas, not the ideas of others. I don’t want to waste my time tinkering with my ZK; I’d rather dive into the work itself. My peak cognition is behind me. One day soon, I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • 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 :)

  • Hey, this is great! I've been trying to decide whether to use Zettlr or The Archive--Zettlr has some disadvantages, but having these functions embedded is a huge advantage--so maybe this will resolve that for me.
    I can't get the tag search to work, though! I get an error: "Prompt With List failed with no result Macro "Insert Tag" cancelled (while executing Prompt With List "" from Variable "ZettelkastenTags")." I don't have much familiarity with KM, so I don't know how to interpret this. Can anyone help?

  • @Ruddiger, if you are trying to get help with then "Insert Tag" KM macro, you placed your question/request under the wrong message thread. This tread is about inter-note links, not tags. The message thread you want is https://forum.zettelkasten.de/discussion/179/quick-insertion-of-tags-with-type-ahead-search-using-keyboard-maestro.

    Once in the appropriate discussion thread, you'll see that there are 2 parts to the "Insert Tags" KM macro. 'Tag Collector Macro', which populates the variable ZettelkastenTags which needs to run in the background and 'Tag Selector Macro' which allows selection of the appropriate tag. It seems as you don't have the 'Tag Collector Macro' running. Check-in KM through the preferences for the variable ZettelkastenTags to see what is populated.

    I could be completely off base. This is my initial troubleshooting tips.

    Will Simpson
    My zettelkasten is for my ideas, not the ideas of others. I don’t want to waste my time tinkering with my ZK; I’d rather dive into the work itself. My peak cognition is behind me. One day soon, I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • Thanks! Working now.

  • This is so great - and is working in my nvALT set-up. Thanks.

  • New to the Forum and The Archive. Can one of you fine gentlemen point me in the direction of the latest, greatest version of this macro. Been some months since there was an update?

  • Another new user thanks you for these great macros. @Will, is it possible to alter your macro slightly so that the pasted link has the format "[[UID]] Title"? I like to see the title for clarity, but - as you and @Sascha point out, I think it's better if it's not part of the actual link. I'm just getting to know Keyboard Maestro through this forum, so I'm not sure where and how I would make this tweak.

  • @JenniferC, @Daveb08, which macro are you referring to? There are 3 referred to in this tread.

    Will Simpson
    My zettelkasten is for my ideas, not the ideas of others. I don’t want to waste my time tinkering with my ZK; I’d rather dive into the work itself. My peak cognition is behind me. One day soon, I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • @Will said:
    @JenniferC, @Daveb08, which macro are you referring to? There are 3 referred to in this tread.

    For me, it’s the ‘insert note link’. Thank you!

  • @JenniferC Maybe you figured this out already, but you can make this change with a few edits to Will's script:

    1. In the "Prompt with List from variable "tmp"" action, change to Variable link to to Source
    2. delete the "Get Substring of Variable "link" action
    3. in the "Insert Text" action, change "%Variable%link%" to "%Variable%tmp%"

    In the end it should look like this:

  • Thank you, @argonsnorts! That is exactly what I was looking for. It would have taken me a long time to figure it out. And thanks again, @will, for the original macro - indeed the "Insert Note Link" as @Daveb08 identified.

  • I've since revised my workflow a bit and now use three different "Insert Note Link" macros.
    The first I use for inline linking where I don't want to interrupt the flow as in this snippet for a note: [[201901231951]] links to the note which chronicles the idea of the future self and future selves.

    Memory dims of our past self, and we haven’t yet met our future self [[201901231951]]. The past self had better write for the future one making the same accommodations as for a forgetful acquaintance or a busy boss.

    The second and third macros are self-explanatory and I think are more what @Daveb08 and @JenniferC are looking for.

    Thanks, @argonsnorts for helping out. I think you'll find the [[ trigger is problematic. I recommend switching to [[[.

    This is v2.0

    Insert Inline Note Link (UID only) [[202008011415]]

    Insert Title 1st Note Link - Zettelkasting Dashboard [[202008011415]]

    Insert UID 1st Note Link - [[202008011415]] Zettelkasting Dashboard

    Here is a link to all of these macros. Insert Link Trivecta

    Will Simpson
    My zettelkasten is for my ideas, not the ideas of others. I don’t want to waste my time tinkering with my ZK; I’d rather dive into the work itself. My peak cognition is behind me. One day soon, I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • Will- thanks so much!

    Dave B

  • Just wanted to say "thanks" to @Will and others who encourage the use of Keyboard Maestro, Alfred and other similar programs. I have Keyboard Maestro but wasn't making use of it much. Reading here about some of the "cool" things that could be done with KM inspired me to start going through the training videos. Lo and behold, I discovered a treasure trove! Thanks everyone :)

  • Thanks @Will for the further clarification. The three macros make a tidy system!

Sign In or Register to comment.