URL protocol handlers in basic Ubuntu Desktop
Solution 1
Open ~/.local/share/applications/mimeapps.list
and add a line like:
x-scheme-handler/apt=apturl.desktop
Solution 2
xdg-mime
Maybe more elegant (in this example I use "apt", change it for any other scheme):
- Check registered MIME-types in
/usr/share/applications/defaults.list
. - Add the
apt.desktop
file (here some examples) to~/.local/share/applications/
(user-wide) or/usr/share/applications/
(system-wide). - Build cache database of MIME types handled by desktop files (may need
sudo
):
update-desktop-database
- Register a protocol with
xdg-mime default apt.desktop x-scheme-handler/apt
This will append the new MIME Type for the scheme to either ~/.config/mimeapps.list
or ~/.local/share/applications/mimeapps.list
. You can register the new mime-type for all users on the system sudo xdg-mime install --mode system <xml file>
.
Test with xdg-open "apt://foo.bar"
.
See also Adding a MIME Type.
Related videos on Youtube
Hibou57
Interested in the following topic and technologies: Unicode XML Standard XML formats (e.g. DITA, XLIFF, SVG, …) HTML5 as a portable UI interface platform Isabelle/Isar/HOL Pure Prolog SML Ada Document authoring and management Planning to have experiments in: XML document authoring (text, not data oriented) Generation of Ada and/or ISO‑C programs from Isabelle/HOL proofs Program sources authoring with two‑ways traceability between sources and specifications Publishing commercial applications in the Ubuntu software Centre My active websites are: www.les-ziboux.rasama.org, a French website dedicated to the Arabic language (also comes with some software and Ada topics) www.lasidore.rasama.org, a tagless XML online editor, which comes with an English and French versions bulleforum.net, a French general purpose forum (also comes with scientific, technical and social topics).
Updated on September 18, 2022Comments
-
Hibou57 over 1 year
There was a way to register URL protocol handlers with Gconf, which is now obsolete and there seems to be no way to do the same with DConf (or Gsettings, its recommended wrapper).
How do one properly register an URL protocol handlers since DConf?
Additionally, something looks strange to me (as I don't understand it), on my Ubuntu 12.04
The protocol
apt://
should be handled by theapturl
command. It is so with my Opera browser, but only because I added this specific association using the browser's configuration facility. Otherwise, in the rest of the environment:- Running
xdg-open apt://foo.bar
openselinks
(mywww-browser
alternative). - Running
gnome-open apt://foo.bar
opens the Software Center. - Opening
gconf-editor
, I see a key/desktop/gnome/url-handlers/apt
whose value isapturl "%s"
and it's enabled. This configuration seems to be ignored, which is reasonably expected, as GConf is considered obsolete. - Opening
dconf-editor
, I can't see anything related to URL handlers or protocols in/desktop/gnome
It looks a bit messy to my eyes (just teasing with this wording, nothing bad)
What's underneath?
Side note: I'm looking for something which preferably works even when the full desktop environment is not loaded, like when running an i3wm session with only
gsettings-daemon
(and other stuff unrelated to this case) loaded.Update
Another way to “register” a protocol handler is with
*.desktop
files and their MIME-Type; e.g.MimeType=application/<the-protocol>;
.I found a
/usr/share/applications/ubuntu-software-center.desktop
with this content:[Desktop Entry] Name=Ubuntu Software Center GenericName=Software Center Comment=Lets you choose from thousands of applications available for Ubuntu Exec=/usr/bin/software-center %u Icon=softwarecenter Terminal=false Type=Application Categories=PackageManager;GTK;System;Settings; MimeType=application/x-deb;application/x-debian-package;x-scheme-handler/apt; StartupNotify=true X-Ubuntu-Gettext-Domain=software-center Keywords=Sources;PPA;Install;Uninstall;Remove;Purchase;Catalogue;Store;
This one explains why
gnome-open apt://foo.bar
opens the Software Center instead ofapturl
.So I installed this
apturl.desktop
in~/.local/share/applications
:[Desktop Entry] Encoding=UTF-8 Version=1.0 Type=Application Terminal=false Exec=/usr/bin/apturl %u Name=APT‑URL Comment=APT‑URL handler Icon= Categories=Application;Network; MimeType=x-scheme-handler/apt;
After
update-desktop-database
and even after rebooting, bothxdg-open
andgnome-open
still do the same and ignore this user desktop file, which as usual with user desktop‑files, should override the one in/usr/share/applications/
.Maybe there is something special with desktop files specifying
x-scheme-handler
MIME type and they are not handled the usual way.The desktop‑file way does not answer the question.
- Running
-
Hibou57 about 8 yearsYa, I could figure it for HTTP, MAILTO and some others.
-
Vlas Bashynskyi over 7 yearsThere is no such folder. I did a search from root, and didn't find it.
-
Hibou57 over 7 years@VlasBashynskyi, the location of
mimeapps.list
may vary. I would suggest to run a search for the file name. -
mickmackusa over 2 yearsThanks for finally making your first post after more than 7 years of being a member here. Please take the tour. It is good to post resolving answers, but it is always more valuable to the asker and thousands of future researchers if you can support your answer with legitimate external documentation or a break down of how/why your solution works. If you can improve your answer, please edit your answer at any time, as many times as needed (there is no limit).