# Using a custom URL handler on Windows for any scripting purpose

Similar to the macOS post on this, Windows has the option to setup a custom protocol handler. Part of this requires writing a script to target, but that is usually left for the person implementing this to worry about (custom paths and search options, etc.).

As for putting such a script into use, the main trick is to add the following entries (or similar) to the Registry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\zettel]
@="URL:Zettel Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\zettel\DefaultIcon]
@="C:\\Program Files\\ZettelProtocol\\handler.exe,1"

[HKEY_CLASSES_ROOT\zettel\shell]

[HKEY_CLASSES_ROOT\zettel\shell\open]

[HKEY_CLASSES_ROOT\zettel\shell\open\command]
@="\"C:\\Program Files\\ZettelProtocol\\handler.exe\" %1"


Save the above as "zettel.reg", and update paths as needed. Then just import the file (double clicking it should do the job), and you have a new protocol available.

That's literally it, nothing else is needed. The "%1" above is the full URI that was activated (all of zettel://202005271955) so the script/program can parse this for a valid link, do whatever searching/database lookups it wants, and then can open the default editor for any file it finds.

• edited May 2020

That's rad! Didn't know it would be this simple!

What if you neither have a proper compiled .exe, or the knowledge to produce one yourself? Could this work with scripts? Maybe invoking a Python script? What would the call look like in that case? (On *nix, you'd just have something like python /path/to/script %1, but I'm not sure about Windows's open commands.

Also, do you have to fill in e.g. zettel:// into this line?

"URL Protocol"=""

Post edited by ctietze on

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

• Using a script should work just the same, you just may need full paths if python is not setup in the Windows PATH (works oddly similar to linux in that regard). C:/Python27/python.exe /path/to/script %1 or similar, that would do it. Depending on the script, it could work for both Windows and Mac, even.

And the settings I have above are what I have on my computer, I just exported them as is. I can use the Run box and enter "zettel://20200528113931" and it fires my custom script (I use AutoItScript to do the work there, and it has a compile to exe feature).