Zettelkasten Forum


Link to any file on my computer?

edited July 2020 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 2020

    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 areas: Attention Horizon, Productive Procrastination, Dzogchen, 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 areas: Attention Horizon, Productive Procrastination, Dzogchen, 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 areas: Attention Horizon, Productive Procrastination, Dzogchen, Non-fiction Creative Writing
    kestrelcreek.com

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

  • @Basil said:
    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.

    @Basil , I tried this with Keyboard Maestro, but I get the annoying "[This app] does not have permission to open this file," whereas with the Hook app, https://hookproductivity.com, it works great. Am I missing something or doing something wrong? I'd prefer Keyboard Maestro for the same cost, as it can do so much more, but only if it works. Sardonic grin. I'm in the free trial for both apps.

    With abandon,
    Patrick

  • @DeaconPatrick Could be modern macOS restricting Keyboard Maestro from doing some things. Check your Security & Privacy settings from "System Preferences", and if it includes Full Disk Access and maybe Accessibility for Keyboard Maestro

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

  • @ctietze said:
    @DeaconPatrick Could be modern macOS restricting Keyboard Maestro from doing some things. Check your Security & Privacy settings from "System Preferences", and if it includes Full Disk Access and maybe Accessibility for Keyboard Maestro

    Aye, I've gone through all tabs in the various security and privacy settings and they are all checked, and mostly match Hook's permission requests. Under "automation," Hook asks for more (Sys. Pref.; Finder, NotePlan3) vs KM (System Events; Finder).

  • @DeaconPatrick, I agree with @ctietze: It definitely sounds like a macOS permissions issue.

    I have read a few times that this system is sometimes a bit buggy (not just with Keyboard Maestro but also with other apps), so that an actual permission is missing, even though the corresponding checkbox is checked in System Preferences.

    Here is some troubleshooting information from the Keyboard Maestro forums:
    https://forum.keyboardmaestro.com/t/tip-resolving-big-sur-accessibility-security-and-other-issues/20159

    I vaguely remember having had a similar issue with Alfred some time ago. If I remember correctly, unchecking and rechecking the relevant checkbox (as mentioned in that post) fixed the issue for me back then.

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

  • Thanks, Basil. I have played with them and the issue remains. That's as much fiddling as I'm willing to do with software I'm trying out, and quite a bit more than I'd normally give it. Hook works every time, in every app, so I'm set, though it's a one trick pony, it's a one trick pony that isn't lame. Grin.

    With abandon,
    Patrick

Sign In or Register to comment.