Zettelkasten Forum


How can I insert a link in a note that will redirect me to a document in my mac?

Hi again!
I see that if I drag a file into de note, it creates the text for a link. Adding one single squared bracket makes nothing and adding two redirects me into "The Archive" itself and not to the original file outside of it.

Thank you so much in advance again for your help!!

Comments

  • I'll be working on that, but drag & drop is not yet as useful when you want to link to external files. You'd have to use regular Markdown links for that:

    Result of drag & drop:

    /Users/ctm/Downloads/the-file.mp3
    

    Format of a Markdown link: [clickable text](http://url.com/)

    Instead of http://, you use file:// for local links; so you end up with (note the three /):

    [hello link! click me!](file:///Users/ctm/Downloads/the-file.mp3)
    

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

  • Thank you Christian, very kind of you.
    A simplified way of doing this would be very welcome I think, but I really appreciate the help anyways!

  • I suggest using Automator to make a Finder Quick Action. Put the following code in a bash shell script and a link to the name and file path are copied to the clipboard, markdown style. After the Quick Action is installed/saved to something like "MD - Make File Path," simply right-click on the file, choose "MD - Make File Path," and type Cmd+V into your note to paste the link.

    See attached screenshot and code. I hope this helps!

    #!/bin/bash
    
    FILE="$1"
    NAME=$(echo "${FILE##*/}")
    echo "[$NAME](file://$FILE)"
    

    MD - Make File Path

  • Brilliant!
    @crankygeologist your solution circumvent the biggest caveat of file URL as the service also grabs the non-URL-encoded version of the file name.

    The other caveat (link is broken if file gets renamed) remains, but is less of a concern (to me at least).

    Thank you for sharing this!

  • After realizing this doesn't output a URL-encoded link, I searched the web and found a solution on StackOverflow and putted together this AppleScript snippet:

    tell application "Finder" to set fileName to name of (get selection as alias)
    tell application "Finder" to set filePath to URL of (get selection as alias)
    set the clipboard to "[" & fileName & "](" & filePath & ")"
    

    Here is a more readable rendering:

    screenshot

    This outputs a clickable file:/// link to the clipboard.

    You can use this "script" (if I dare to say) with Automator, as described by @crankygeologist. I personally use it with BetterTouchTool.

    BTW, you can get BetterTouchTool at 20% discount with the code BTT_MPU
    I can't tell how long it will last though.

    Thanks again @crankygeologist for the inspiration!

Sign In or Register to comment.