Link to external files

Hi,

Is there a way to create links to files outside the obsidian directory, particularly where the path contains spaces?

So far I can get such links to work using [readable name](file://path-here) but the link doesn’t render in preview and is only clickable in editor mode. Simply using file://path-here doesn’t render as a link or work in the editor.

This looks like I might be trying to achieve the same as the OP of this graveyarded bug and would be related to this post as well.

Any help is greatly appreciated. Loving Obsidian so far but this would be really useful for my job and I’m sure others would find it to be too.

Cheers
Ave54

EDIT: I have resolved my own issue. Discovered within the format help doc that you can escape spaces in links by enclosing it in <> (in much the same way as windows uses “” to enclose file paths with spaces).

Therefore it is possible to use a markdown link to link to external files like so: [pretty filename](<file:///path to file with spaces.extension>) which will create a clickable link in preview titled “pretty filename”.

Note that the link doesn’t work in editor mode (ctrl + click registers it as a link but opens a windows dialog “you’ll need a new app to open this app link”. I assume this is a bug.

2 Likes

I found the most reliable way to do links is to do a fully converted webbrowser style URI. In this, spaces become %20. There is no easy way to type such a link, but I found and adapted a Windows shell extension so I can send any file to the clipboard as a pastable Obsidian link.

I can post C# source code later. Could also post a binary program, but I don’t know right ways to do that.

1 Like

Thanks, replacing spaces with %20 solved the problem. Just need to find a way to simplify link conversion.

This was my solution, in Windows:

using System;
using System.Windows.Forms;
using System.IO;

namespace AbsoluteUriGenerator
{
  class Program
  {
    [STAThread]
    static int Main(string[] args)
    {
      if (args.Length != 1)
      {
        var executableName = typeof(Program).Assembly.GetName().Name + ".exe";
        Console.WriteLine("Usage: {0} pathToConvert", executableName);
        Console.WriteLine("Example: {0} \"C:\\foo\"", executableName);
        return 1;
      }

      var path = args[0];
      Console.WriteLine("Resolving file:// URI of path: {0}", path);
      var uri = new Uri(path).AbsoluteUri;
      var name = Path.GetFileName(path);

      Console.WriteLine("Setting clipboard to resolved file:// URI: {0}", uri);
      Clipboard.SetText("["+name+"](" + uri + ")");
      return 0;
    }
  }
}

Adapted from https://superuser.com/questions/297060/generate-file-uris-in-windows-explorer

If you compile this, you can copy that to your shell:sendto folder, then right click on any file and click send-to and click Copy_URI. Gives you any file on your computer.

1 Like

I’m not able to click the link in Preview even after enclosing the absolute path within <>.

e.g. [Perspective Taking](<file://Users/JL/Documents/ACT Immersion/Perspective Taking.pdf>)

Using version v0.10.8

Is it supposed to open up the file with the system default app?

Hi,

There is a problem mentioned before, ther are spaces in your URI.
A new plugins “File path to URI” can help you.
Fules

It works now, Thank you Fules!

On macOS you can create an AppleScript script, which saves URLs of selected files in Finder to the clipboard:

tell application "Finder"
    set _sel to (get selection as alias list)
    set _urls to {}
    repeat with _file in _sel
        set _url to URL of _file
        set end of _urls to _url
    end repeat
    set AppleScript's text item delimiters to return
    set the clipboard to (_urls as string)
end tell

Save this script as Copy URLs.applescript and put it into the ~/Library/Scripts/Applications/Finder/ folder. Now you can select a file in Finder and run the script via the Script menu, located in the OS menu bar (make sure the option “Show Script menu in menu bar” is checked in the General tab of the Preferences dialog of the Script Editor app). The URL of the selected file will then be copied to the clipboard and can be pasted into an Obsidian document. You may also assign a keyboard shortcut to the script.

1 Like

It works beautifully! Thank you so much!

Is there a possibility to open .pdf on exact page?

on web browser works
file://path_to_file/File.pdf#page3
on windows
AcroRd32.exe /A page=3 “c:\path_to_file\File.pdf”

How to do that in obsidian? :slight_smile:

Hi,

I have never tried, but the “Better PDF plugin” is about it.
Read it, how I remember he uses the “#page” format.
Füles

1 Like