Bypass Bases Sandbox to open file:/// URI links

I have spent the last hour or so trying to open URL encoded file:/// URI paths even with the most agressive bypass techniques GPT could think of and none could go through in Card View.
Apparently, as the bot says, this is an Electron sandbox issue…?

Use case: PDFs, movies with posters as covers and clicking path link below it to open the files with system set program.
(I didn’t figure out yet, how to click the image and open the PDF or play music or video, so I add another prop below the cover image.)

YAML example:

thumbnail: "[[coverimage.jpg]]"
path: "file:///Y:/path/to/video/filename_url_encoded.avi"

Apparently, you cannot have <> flankers here, only in the main body of the note. I had URL encoded path put there (through Python script to create my md files).

In the main body in the note, clicking
[![[coverimage.jpg]]](<file:///Y:/path/to/video/filename.avi>) construct works.
Opens video in external vid player, even if it is an mp4, but clicking is more easily done in Reading Mode, of course.
Here, if you add the <>, no URL encoding is needed.


Objective: Clicking Path Link to Open files through Bases Cards View

Tried what the doctor should order first:

1. link(path, "▶ Play Video")
2. something similar to the above (I forgot)
3. html("<a href='" + path + "' target='_blank' rel='noreferrer'>▶ Play Video</a>")

Didn’t work. Clicking the link did nothing.

I tried 7-8 different methods. Nada. Then, finally…


What works

Create a launcher.bat file and keep it safe (you can put it in your vault in some SYSTEM/subfolder):

@echo off
:: Remove the protocol prefix (ms-openlocalfile:) from the passed argument
set "filepath=%~1"
set "filepath=%filepath:ms-openlocalfile:=%"
:: Remove surrounding quotes if any
set "filepath=%filepath:"=%"
:: Launch the file with the default application
start "" "%filepath%"

Then create a text file, “New Document.txt” or whatever, with:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\ms-openlocalfile]
@="URL:Open Local File"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\ms-openlocalfile\shell]

[HKEY_CLASSES_ROOT\ms-openlocalfile\shell\open]

[HKEY_CLASSES_ROOT\ms-openlocalfile\shell\open\command]
@="\"C:\\Path\\To\\launcher.bat\" \"%1\""

Here in the last line, add the full path to your launcher.bat file. Note the \\ in the path.
Rename this file to ms-openlocalfile.reg and double-click it to register it.

Then, go back to your Base formula, and add html('<a href="ms-openlocalfile:' + path + '">▶ Play Video</a>'). You need to add your own property. It may not be path like mine and you can change▶ Play Video if it’s not a video file, of course.

Done.

2 Likes

The above was for Windows. Some similar method can be tried along these lines for Mac and Linux, I reckon.

For i(Pad)OS and Android, I think we need this restriction lifted. I tried with a CodeScript Toolkit .ts to intercept link openings, but couldn’t hack it. There you’ll need to go into your note and use the main body content links (possibly with VLC if you run a server on your PC).

EDIT. I forgot to say clicking URL link from properties also worked.

Turns out the original batch-file approach fails for filenames with accented characters (é, ö, á, ñ, etc.) because cmd.exe’s default code page corrupts UTF-8 bytes.

Here’s the updated method, then:


What works (diacritics-safe version for Windows, Mac, and Linux)

Here’s the fix using PowerShell:

Step 1: Create launcher.bat (you can keep it in your vault, e.g. SYSTEM/SUBFOLDER/launcher.bat)

@echo off
:: Enable UTF-8 for diacritic support (é, ö, á, ñ, etc.)
chcp 65001 >nul
:: Pass the argument to PowerShell for proper UTF-8 and URL-decode handling
:: Using %~dp0 ensures launcher.ps1 is found in the same directory as this .bat
powershell -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "%~dp0launcher.ps1" "%~1"

Step 2: Create launcher.ps1 (same subfolder)

param(
    [Parameter(ValueFromRemainingArguments = $true)]
    [string[]]$Args
)

# Combine all arguments (in case the path was split due to spaces)
$raw = $Args -join ' '

# Remove the protocol prefix (ms-openlocalfile:) if present
$raw = $raw -replace '^ms-openlocalfile:', ''

# Remove surrounding quotes if any
$raw = $raw.Trim('"')

# Check if this is a file:// URL and extract the local path
if ($raw -match '^file:///(.+)') {
    $path = $Matches[1]
    $path = $path -replace '/', '\'
} else {
    $path = $raw
}

# URL-decode the path using .NET Uri.UnescapeDataString
# This handles %20 -> space, %C3%B6 -> ö (if percent-encoded), etc.
$decoded = [System.Uri]::UnescapeDataString($path)
$decoded = $decoded.Trim('"')

# Launch the file with the default application
Start-Process -FilePath $decoded

Step 3: Create the registry file (ms-openlocalfile.reg)

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\ms-openlocalfile]
@="URL:Open Local File"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\ms-openlocalfile\shell]

[HKEY_CLASSES_ROOT\ms-openlocalfile\shell\open]

[HKEY_CLASSES_ROOT\ms-openlocalfile\shell\open\command]
@="powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File \"C:\\FULL\\PATH\\TO\\launcher.ps1\" \"%1\""

Important: In the last line, add your full path to launcher.ps1. Use \\ (double backslash) in the .reg file path. Note the key change: this calls launcher.ps1 directly via powershell.exe, NOT launcher.bat. If you want to keep the .bat as a wrapper, you can change it to -File "...launcher.bat" instead, but calling PowerShell directly is cleaner.

Step 4: Go back to your Base formula

Same as before:

html('<a href="ms-openlocalfile:' + path + '">▶ Play Video</a>')

Your path property can be in either format:

  • file:///Y:/path/to/video/filename_url_encoded.avi — the .ps1 strips file:/// automatically
  • file:///Y:/path/with_%C3%B6_diacritics/file.avi — fully URL-encoded works too
  • file:///Y:/path/with_ö_raw_diacritics/file.avi — raw UTF-8 also works (Windows converts to system code page)

Why this works

  • PowerShell receives the URL argument via Windows protocol handler, which converts UTF-8 bytes to the system code page (cp1250/cp1252) — preserving diacritics correctly
  • [System.Uri]::UnescapeDataString() decodes %xx sequences (spaces, percent-encoded accents) that were URL-encoded by your Python script or note
  • chcp 65001 in the .bat fallback ensures UTF-8 compatibility when the batch file is used
  • Works for any language with Latin-based diacritics (Spanish, French, German, etc.)
  • Mac/Linux: Replace the registry step — create a custom protocol handler via LaunchServices.plist (macOS) or a .desktop file / xdg-settings (Linux) that calls a shell script doing python3 -c "import urllib.parse,sys; print(urllib.parse.unquote(sys.argv[1]))" + open or xdg-open.