Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu custom URL protocol handler

I want to ask a question, but I will first show my files

<html>
<body>
<a href="cloudje:firefox">Open firefox</a>
</body>
</html>

My .desktop file:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/usr/bin/cloudjerun -c gedit
Name[en_US]=Gedit
Comment[en_US]=Small, easy-to-use program to access iTunesU media
Name=TunesViewer
Comment=Small, easy-to-use program to access iTunesU media
Icon=/usr/share/icons/hicolor/scalable/apps/tunesview.svg
Categories=Application;Network;
MimeType=x-scheme-handler/cloudje;
Comment[en_US.utf8]=Small, easy-to-use program to access iTunesU media

Tutorial: http://jarrpa.net/2011/10/28/creating-custom-url-handlers-in-ubuntu-11-04-11-10-gnome-3-0/

Ok, this is cool. The .desktop file will be placed in /usr/share/applications. If you execute the command 'xdg-open cloudje:firefox' or something like 'xdg-open cloudje:example', it will always execute gedit using a Python script named 'cloudjerun'. How can I execute firefox using the command 'xdg-open cloudje:firefox'?

Do I need to replace 'Exec=/usr/bin/cloudjerun -c gedit' to 'Exec=/usr/bin/cloudjerun -c %U' or 'Exec=/usr/bin/cloudjerun -c %s' or something?

like image 427
Stephan Meijer Avatar asked Oct 05 '22 05:10

Stephan Meijer


1 Answers

In a desktop file following parameters are possible for Exec

Add...  Accepts...
%f      a single filename.
%F      multiple filenames.
%u      a single URL.
%U      multiple URLs.
%d      a single directory. Used in conjunction with %f to locate a file.
%D      multiple directories. Used in conjunction with %F to locate files.
%n      a single filename without a path.
%N      multiple filenames without paths.
%k      a URI or local filename of the location of the desktop file.
%v      the name of the Device entry.

So in your case you can adjust your Exec entry as you described to the following:

Exec=/usr/bin/cloudjerun -c %u

Note though that %u is the complete uri so e.g. when you run xdg-open cloudje:firefox %u will be cloudje:firefox. Easiest I assume is to adjust the cloudjerun python script removing the first part of the uri before running it.

like image 52
Oliver Sauder Avatar answered Oct 06 '22 20:10

Oliver Sauder