Zettelkasten Forum


Link to any file on my computer?

edited July 30 in The Archive

I know we can link to a media file in our media folder within our directory, but is it possible to link to other files/folders on my machine? Or subfolders within the media folder? Not a programmer here. :wink:

And IF I can, is there a quick way to determine the path of a particular file? Or would it be simpler to use the "Copy Link" feature from dropbox and just link to it in the browser?

Comments

  • edited July 30

    You can use standard macOS URL syntax.

    For folders:

    file:///Users/alex/Dropbox/
    

    For files:

    file:///Users/alex/Dropbox/article.pdf
    

    Another option would be to assign a shortcut to this AppleScript, and run it on selected files/folders - it will copy URL encoded path to your clipboard.

    on path2url(thepath)
        return do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of thepath
    end path2url
    
    tell application "Finder"
        set sel to the selection as text
        set the clipboard to "file://localhost" & my path2url(POSIX path of sel)
    end tell
    

    Alternatively, check out Hook app - it allows to create custom links to pretty much anything.

  • An easier method (on Mac): In the Finder, select the file and press Cmd+option+C. This copies the path to your clipboard.

  • @zvt said:
    An easier method (on Mac): In the Finder, select the file and press Cmd+option+C. This copies the path to your clipboard.

    That method works great. However, I occasionally use spaces in my folder names, which plays havoc with the path in TA. For example, say I paste the following into a note in TA:

    /Users/geoeng51/Dropbox/Sunday Reading/filename.md

    I then need to type "file://" in front of that string, to get TA to recognize it as a path to a file.

    The problem is, the path is only "recognized" to the end of "Sunday", as whatever algorithm is parsing the path name can't deal with spaces.

  • Here is the Keyboard Maestro macro I use for automatically creating "file:///" links you can use in The Archive or in pretty much any other application on your Mac. In addition to getting the path(s) of the selected file(s) in Finder and prepending "file:///", it also converts all characters (such as spaces) that are not allowed in links, so that the resulting link is valid and clickable.

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

  • I use a Keyboard Maestro macro much like @Basil does but is different in that it copies the file first to the zettelkasten/media directory then puts a link in the format of -
    ![](media/file_name_with_underscores_replacing_any_spaces.md)
    into the clipboard for pasting in notes. I do this for portability (the zettelkasten/media folder is in Dropbox and I access it from a few different devices).

    I do see an argument against this workflow as I can't do this and update a file outside of the /media folder. The type of files (PDF's, MP3 pictures, external docx files) I want to have links too in my zettelkasten are all static and have never thought about editing them. But who knows what the future holds. That is unless I had the Keyboard Maestro macro create symlinks. This might create its own issues.

    Will Simpson
    I'm a Zettelnant.
    Research: Rationalism, Zen, Non-fiction Creative Writing
    kestrelcreek.com

  • My Dropbox/zetelkasten folder (1300+ notes) totals 154 MB together with the /media folder which is 152 MB (161 items) of the 154 MB. I don't ever expect space to be a problem. YMMV
    It'd be interesting to see these stats on other zettelkastens. 1300+ notes and only 2 MB. WOW!

    Will Simpson
    I'm a Zettelnant.
    Research: Rationalism, Zen, Non-fiction Creative Writing
    kestrelcreek.com

  • @Will said:
    I use a Keyboard Maestro macro much like @Basil does but is different in that it copies the file first to the zettelkasten/media directory then puts a link in the format of -
    ![](media/file_name_with_underscores_replacing_any_spaces.md)
    into the clipboard for pasting in notes. I do this for portability (the zettelkasten/media folder is in Dropbox and I access it from a few different devices).

    @Will - can you mention the name of your Keyboard Maestro macro that does this? I've downloaded some of your macros but am not sure to which one you refer. Thanks.

  • @GeoEng51 said:
    @Will - can you mention the name of your Keyboard Maestro macro that does this? I've downloaded some of your macros but am not sure to which one you refer. Thanks.

    https://forum.zettelkasten.de/discussion/559/quickly-copy-files-images-to-media-folder-and-create-formatted-media-links-using-keyboard-maestro

    Will Simpson
    I'm a Zettelnant.
    Research: Rationalism, Zen, Non-fiction Creative Writing
    kestrelcreek.com

  • @Will Thank you!

  • @GeoEng51 said:

    @zvt said:
    An easier method (on Mac): In the Finder, select the file and press Cmd+option+C. This copies the path to your clipboard.

    That method works great. However, I occasionally use spaces in my folder names, which plays havoc with the path in TA. For example, say I paste the following into a note in TA:

    /Users/geoeng51/Dropbox/Sunday Reading/filename.md

    I then need to type "file://" in front of that string, to get TA to recognize it as a path to a file.

    The problem is, the path is only "recognized" to the end of "Sunday", as whatever algorithm is parsing the path name can't deal with spaces.

    Yes, that's true...
    It is not an elegant or work-in-all-situations kind of solution; Will's macro is much better for that. Since I don't use it too often, it's sufficient for me. (I think you have to use %20 for the spaces, like in a url.)

  • @zvt said:

    It is not an elegant or work-in-all-situations kind of solution; Will's macro is much better for that. Since I don't use it too often, it's sufficient for me. (I think you have to use %20 for the spaces, like in a url.)

    Yes, that's right. I'd forgotten about that "trick" (replacing a space with %20), but it certainly works.

Sign In or Register to comment.