Zettelkasten Forum


[REQUEST] Convert The Archive's copied links from [[YYMMDDHHMM Title]] to [[YYMMDDHHMM]] Title

edited April 2019 in The Archive

I want to use "[[YYMMDDHHMM]] Title" when linking between notes, since this makes it possible to edit titles in the future, without breaking any existing links.

When using Cmd-C to copy a note title – or when right clicking to copy a note link – the result is YYMMDDHHMM Title or [[YYMMDDHHMM Title]]. Could Textexpander och Keyboard Maestro be used to convert what's in the clipboard to my desired format? Or is this a feature that are on the roadmap for The Archive?

Post edited by ctietze on

Comments

  • Yes! Keyboard Maestro to the rescue. Not exactly what you asked for but it might work.

    Thanks to @kaidoh for the inspiration and Chris Stone who helped with the regex and @Sascha for pointing out that the IDs should be separate from the zettel titles.

    This will convert "201811281633 - Book - The Physics of Life" to "Book -The Physics of Life [[201811281633]]" inserting it into a note, making the ID a link. Not sure why notes are not created like this in the first place. But I'm going with it for now.

    Setup In Keboard Mastro

    Macro in action - Choosing a Link

    The Results

    Here is the macro file
    The Keyboard Maestro macro file.

    Will Simpson
    I must keep doing my best even though I'm a failure. 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 - I've notice several of your Macros run the shell script "cd /Users/will/Dropbox/zettelkasten/
    ls | sed -E -e 's/.[^.]*$//' -e 's!^([0-9]+)[[:space:]-]+(.+)![[\1]] \2!'" or something similar.

    What exactly are you pointing to so I can figure out what the script should look like on my computer?

  • Will - I figured it out and what my problem was. Thank you for these resources!

  • edited September 2019

    Hey @Will, can I ask a favor? I would like a macro that does exactly this but only outputs the ID in brackets, without the title at all. I'm trying to make sense of your sed statement and it's baffling me. Could you tell me what that would look like?

    Thanks!

    Edit: I found elsewhere the "inline note link" macro, which does what I need so I suppose this request is redundant. But I wouldn't mind seeing how you would do it in sed as well if you happen to have the time.

  • @mediapathic, try this:

    ls | sed -E -e 's/.[^.]*$//' -e 's!^([0-9]+)[[:space:]-]+(.+)![[\1]]!'
    

    i.e., just leave out the \2 at the end (which inserts the matched title).

  • @mediapathic -
    @msteffens is correct. Just leave off the \2. In the sed statement. There are 2 'Groups' here defined by the ( ). Group 1 is ([0-9]+) the note id number and Group 2 is (.+) the note title.

    At the end is the replacement part of the sed statement. This is where the Groups are manipulated. This sed statement says output [[ then Group 1 then ]] using the switch \1 which calls Group 1. You could just as easily output just the note name by replacing Group 2 with Group 1.

    The sed statement in the "inline note link" macro outputs the same result as the "insert note link" but KM only outputs the first 16 characters of the captured variable which happens to be the "[[201906131630]]" portion of the whole variable. Sloopy, but that was my state of knowledge at the time.

    This is not meant to be a sed tutorial. I am not a sed expert although I sometimes pretend to be one on the forum.

    Will Simpson
    I must keep doing my best even though I'm a failure. 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 I am new to Keyboard Maestro. The Archive has brought it to my attention, and so now I have downloaded it and am downloading some Macros from this forum both to use and explore how KM works.

    My question. With this Macro, is it possible to change the output from Title [[YYMMDDHHMM]] to [[YYMMDDHHMM]] Title?

  • @DavidWJ Welcome to the Keyboard Maestro rabbit hole.

    The solution is in the Execute Shell Script action. The end of this command is where the action is. The \2 signifies the capture group that contains the notes' name and the \1 represents the timestamp of the note. Notice that the "\1" is surrounded by [[]] for making it a link. You can easily switch the positions or leave the name out entirely and only make a link. I have switched positions of title and link back and forth a couple of times and still can't settle on what is more aesthetically pleasing.

    sed -E -e 's/.[^.]*$//' -e 's!^([0-9]+)[[:space:]-]+(.+)!\2 [[\1]]!'

    Will Simpson
    I must keep doing my best even though I'm a failure. 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 Many thanks for the quick reply, and explaining how the shell script works. I laugh at you changing the script back and forth. That sounds like me through and through. But again, many thanks. I look forward to experimenting!

Sign In or Register to comment.