ewa / GeneralURLHandler

A "shim" tool to bind to URL protocols in macOS and pass "open" requests to other user-chosen programs. A fork of jwbargsten's ZettelURLHandler, which does the same thing in the specific context of a Zettelkasten note taking app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GeneralURLHandler

About

This tool exists to be an intermediary between macOS's URL-opening functionality and programs that one might wish to handle/execute/receive those URL-opening tasks. Honestly, it shouldn't have to exist at all, because all it's meant to to is (a) have tasks delegated to it, and then (b) re-delegate those tasks to another program, however it doesn't /seem/ to be possible to get the behavior I want without it.

This is a fork (stripped-down version) of Joachim Bargsten's' ZettelURLHandler, which does this specifically for opening zettel:// URLs describing Zettelkasten notes in vim.

My intended application is quite similar: I use the org-mode tool family in Emacs for note taking and organizing, and there is a scheme called org-protocol which lets programs outside of Emacs pass information in by calling emacsclient and passing the information in as a URLon the command line. That makes adding "capture to org" functionality to arbitrary programs a lot easier, because any program that can be configured to either directly execute a command or try to open a URL can do it. Except that macOS has to be precious and add an extra wrinkle to the process.

Why is this even necessary?

Most desktop environments (OSes) provide mechanisms for a user to say "open this file" or "open this URL (URI)" and then let the system identify the preferred program to use for the task. The part of a URI before the : is called the "scheme", and your system is almost certainly configured to map http, https, (and a bunch of others) to a preferred web browser, and mailto to an e-mail client (or webmail site), among others. There are processes for defining "official" widely-recognized URI schemes, but also anybody who wants to can make up their own unofficial ones, and many apps do so as a way of labeling (and sometimes accessing) their contents and functionality. Every OS / desktop environment handles it differently, but they all have some way of saying "URLs with scheme foo should be opened by invoking program bar." Normally, there's a list (probably a per-user list, with another system-wide defaults list as a fallback) of such mapping somewhere, and you, the user, can edit it to get what you want.

Not on macOS, at least not anywhere that I've found. AFAIK, there's no user-accessible setting for it. Not through a GUI, not on the command line, not in a configuration file, not programmatically through an API. Instead, applications declare the schemes they "claim" as part of their static metadata, and at some point during the installation and/or application startup processes, the OS looks at an application's metadata (Info.plist) and updates its bindings accordingly. I'm sure this is seen as security feature, because it forces applications to pre-declare what schemes are "for them," making it harder for a malicious application to "hijack" URI-openining commands that you wouldn't expect or want it to be receiving. Which gets us to this, an app the exists only to say "I claim URI scheme org-protocol" (or anything else you edit it to) and then when it gets one, really invoke whatever other program you tell it to.

Incidentally, after starting on this, I found these instructions by Xu Chunyang which an even simpler AppleScript DIY version of the same thing. That's probably better in most regards, but this version has the advantage that you could download a fixed binary (if I provided them, which I ... err ... don't yet) and reconfigure how emacsclient (or whatever program you want) is invoked through Apple's normal defaults mechanism without needing to edit the source code. Unfortunately, and seemingly by design on Apple's part, the one thing you can't do without editing source code (or at least app bundle files) is change what URI schemes it responds to. Bah.

About

A "shim" tool to bind to URL protocols in macOS and pass "open" requests to other user-chosen programs. A fork of jwbargsten's ZettelURLHandler, which does the same thing in the specific context of a Zettelkasten note taking app

License:Apache License 2.0


Languages

Language:Swift 98.8%Language:Makefile 1.2%