Zettelkasten Forum


[FEATURE REQUEST] Link to a file in a note

Dear Christian and Sascha,
as far as I can tell, at the moment it's not possible to create a clickable link to a (non-txt) file on my computer within a note. Through drag&drop the location of the file on my computer will be created in the note, but just as plain text, it's not clickable. Even if I add the syntax "![](file location)" I can't open the file through clicking on the location text.
Are you planning to change this in the future?
Best wishes,
Vinho

Comments

  • Well, I do have an open task to deal with file-system links differently in the future. When the new Markdown highlighter is ready, I think it's time to tackle that. Will take some time, though.

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

  • In the meantime, if you need a clickable link in The Archive, you can insert a file:/// link to the file instead of just the file path. They are basically a URL-encoded version of the file path and look something like this:
    file:///Users/basil/Desktop/Screenshots/Screen%20Shot%202018-12-03%20at%2008.58.51.png
    (for the file /Users/basil/Desktop/Screenshots/Screen Shot 2018-12-03 at 08.58.51.png)

    When you click on such a link in The Archive, the file is not opened directly, but it is revealed in Finder. A quick ⌘↓ (or ⌘O) then opens the file.

    Of course, creating these links by hand would be pretty tedious. Fortunately, there is (like for many other problems) a Keyboard Maestro based solution:
    Copy encoded URLs of selected files

    These links do not only work in The Archive, but in almost all other applications as well. I often include such links to files (or folders) in OmniFocus tasks, calendar events, etc. and find them immensely useful.

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

  • Thanks, Basil – that is a very helpful post!
    If I understand correctly, the file:/// link just works if there are no spaces in the file name or if you fill those spaces with %20 every time. That is indeed very tedious. I haven't used Keyboard Maestro so far and probably wouldn't buy it just for this purpose, but thanks for letting me know about this option.

    In the meantime, I have also learned about the option to put files into the "media" folder in my archive and then link to them with ![](media/filename), which would be a relative link that would also work on other devices.
    Again, the file name can't have spaces.

    Thanks a lot!

  • That's basically the trick: to "HTML-URL-encode" the path, which includes replacing spaces with %20.

    URL encoding the text or file from the clipboard can be automated with various tools.

    A combination of "take the selected file from Finder" and "make it a file:// URL":
    https://stackoverflow.com/a/9617705/1460929

    You can put this into a new Service in Automator and then assign to it a shortcut from System Preferences > Keyboard (instructions]. Et voila! No Keyboard Maestro needed, even though KM is great :)

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

  • That's great, thanks!

  • Update on this: spaces in filenames work better now since v1.6.0 is in the cutting edge channel. You will likely not need to convert file names anymore.

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

  • @ctietze: Thanks for the update! I have since then made it a habit to not use spaces in filenames, so for me it actually won't change anything ;)

  • @Vinho I’m not sure if this was mentioned, but creating a path for any (non-image) file you want to reference in a Zettel is really simple, at least in the MacOS. You highlight the file in Finder, then click on option-command-C. This copies the file path, rather than the file. You then go to your note and hit command-V to paste the file path.

    Here is an example with one of my Zettels. Say I wanted to reference a letter that I wrote to my mom in 2017, while I was living in Australia. The above process would yield the file path:

    /Users/johnsobkowicz/Documents/Mom/2017.12.12 Letter to Mom.pdf

    As pointed out by @Basil, I need to add file:// in front of that path and I also need to replace all spaces with %20, to get

    file:///Users/johnsobkowicz/Documents/Mom/2017.12.12%20Letter%20to%20Mom.pdf

    (That is where the file:/// comes from).

    Clicking on that link opens a Finder window with the desired file highlighted.

  • @GeoEng51: Thanks for the tip with OPTION-CMD-C, I didn't know that! Have so far always right-clicked the file, then pressed OPTION in the context menu and then chosen "Copy ... as Pathname". Your method is much quicker!

  • @Vinho - You are welcome! I think I learned it from @Will, though, or at least from someone else on the forum, so should give credit elsewhere. :smiley:

Sign In or Register to comment.