This question is a decade old(!) but a Google search brought me here so I wanted to mention something I just discovered.
Platypus is an open source tool that allows you to create standalone "Applications" from a shell script or other scripting language. Although it's really just a script wrapper, it does enable some cool things like dialog boxes and menu bar items.
Critically, it even enables you to register your "app" as a handler for your own custom URL scheme. From the docs:
Register as URI scheme handler makes the app register as a handler for URI schemes. These can be either standard URI schemes such as http or a custom URI schemes of your choice (e.g. myscheme://). If your app is the default handler for a URI scheme, it will launch open every time a URL matching the scheme is opened. The URL is then passed to the script as an argument.
Setup is dead simple. Just provide your script, enter your desired scheme name on the advanced settings page and then click to build the app (it's all automated). Everything after the scheme and forward slashes will be passed as the argument to your script.
For example, you could use the following bash script as a handler for the "speak://" protocol.
#!/usr/bin/env bash
# The 'say' command on macOS will speak the provided text through the speaker
say $1
You could invoke it by entering speak://say-something-funny
into your browser or by using the open
command on the command line:
$ open "speak://hello-from-the-command-line"