So, start with the file path:
The problem here is that URLs can’t have spaces in them. When I paste it into Things, it assumes that the space is the end of the URL and tries to link to a file named ‘Test’ instead of ‘Test File.txt’:
We could just never use spaces in our file paths, but the Mac has supported spaces in file and folder names since time immemorial. Instead, we can get around this by URL encoding the path, replacing the space with
%20. You could do this manually, but that would be a pain and we’d also have to replace any other characters that aren’t valid in a URL. Instead, we can use URL encoding software to make all the necessary substitutions for us. If you want to play around with it, there are websites that will URL encode text for you. If this is something you want to make part of your workflow you probably want to script it (this can be done using the Filter action in Keyboard Maestro and setting it to “Percent Encode for URL”).
This gives us:
In order to make Things or other programs that automatically convert URLs to links recognize this as a URL we need to put
file:// in front of the URL-encoded path (just like URLs for websites have “http://” at the front).
Now when I paste this into Things it recognizes the whole string as a URL and doesn’t stop at the space:
Note that when I hover over the link, Things automatically decodes the URL turning
%2F into a slash and
%20 into a space:
If I click the link it will open my Documents folder in a Finder window with
Test File.txt selected. ⌘-O will open it in whatever the default app is for that file type.