17

I am attempting to port one of my hobby project to linux. Preferrably to Mono since it is written in C#. But I am looking into Python as well.

One of the feature of the application is that it needs to associate with a custom protocol so the application is invoked when the user clicks links like this on the app's website:

myapp://module/action

A custom protocol like this, this and this.

How can that be done in linux/unix systems? Can I associate a system-wide handler like in Windows? or does it need to be browser-dependent?

Can't find anything on Google. And I am utterly clueless at linux programming.

I need some pointers. Thanks!

Community
  • 1
  • 1
chakrit
  • 61,017
  • 25
  • 133
  • 162

4 Answers4

9

In the ideal situation, this sort of thing is handled by the desktop environment (KDE, GNOME, XFCE), and Firefox respects those settings---it should do so on Ubuntu, Fedora, and OpenSUSE, at least. YMMV:

Integrating a new URIs Scheme Handler to GNOME and Firefox

Adding a protocol handler for firefox (KDE)

James Cape
  • 704
  • 3
  • 11
  • Ah, this looks promising... will try when I have access to a fast workstation on Monday :-) Thanks! – chakrit Jan 04 '09 at 20:14
  • Unfortunately, the first link (people.w3.org/…) relies on `gconf`, which is obsolete and should not be used any‑more. – Hibou57 Aug 21 '14 at 06:32
  • First link doesn't seem to work anymore. I can call gconftool-2, but there is no apparent effect – Stefan Reich Jul 30 '17 at 14:17
4

The manual way to doing it for firefox:

open firefox
type in about:config to location bar
add new string
name:  network.protocol-handler.app.myapp
value: /path/to/program
Cheery
  • 24,645
  • 16
  • 59
  • 83
  • This doesn't do anything – Stefan Reich Jul 30 '17 at 14:16
  • That should work: when you follow link to `myapp:xyz` it should run program `/path/to/program` with argument `xyz`. Note that you may need to also specify `network.protocol-handler.expose.myapp = true` and/or `network.protocol-handler.internal.myapp = true` according to the use case you want to handle. – Mikko Rantalainen Nov 30 '20 at 12:37
1

There's not going to be a single answer, because that will be happening at the X window manager level at best. In general, you're going to need to have some chunk of code you can put into your path, and associate the name with the protocol. Have a look at the about:config page, which is where the handlers are set up.

That's really all that Windows does too, it's just that stuff is in the registry.

This looks like a decent drescription for Firefox.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
  • 1
    The window manager has absolutely nothing to do with opening links. – derobert Jan 04 '09 at 20:11
  • Which window manager are you speaking of, derobert? And what part of "at best" did you find difficult? – Charlie Martin Jan 05 '09 at 02:57
  • @Charlie Martin: "...that will be happening at the X window manager level...". The X window manager has nothing to do with opening links. I think you meant 'desktop environment' or somesuch (gnome, kde, etc.) – derobert Jan 07 '09 at 19:27
  • Um, where do you think the desktop environment is? Check your terminology; reading the various Wikipedia articles on X would help. Look especially at ICCMP, ICE, and window and session management. Or note that KDE, Gnome, etc are types of window maangers here: http://xwinman.org/ – Charlie Martin Jan 08 '09 at 04:03
  • @CharlieMartin and none of the window managers have anything to do with opening links – user253751 Apr 15 '21 at 09:38
  • You bet, son. Now go look up what a desktop environment is in X. Here, I'll help: https://en.wikipedia.org/wiki/Desktop_environment#Desktop_environments_for_the_X_Window_System – Charlie Martin Apr 18 '21 at 14:04
-6

Can I associate a system-wide handler like in Windows? or does it need to be browser-dependent?

It has to be browser-dependent. There's no cross-browser way of associating URL handlers in Linux.

Ross
  • 9,652
  • 8
  • 35
  • 35