Ubuntu 自定义 URL 协议处理程序

Ste*_*jer 5 linux url ubuntu protocols handler

我想问一个问题,但我会先展示我的文件

<html>
<body>
<a href="cloudje:firefox">Open firefox</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的 .desktop 文件:

[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
Run Code Online (Sandbox Code Playgroud)

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

好的,这很酷。.desktop 文件将放置在 /usr/share/applications 中。如果您执行命令“xdg-open cloudje:firefox”或类似“xdg-open cloudje:example”的命令,它将始终使用名为“cloudjerun”的 Python 脚本执行 gedit。如何使用命令“xdg-open cloudje:firefox”执行firefox?

我是否需要将 'Exec=/usr/bin/cloudjerun -c gedit' 替换为 'Exec=/usr/bin/cloudjerun -c %U' 或 'Exec=/usr/bin/cloudjerun -c %s' 或其他内容?

Oli*_*der 6

在桌面文件中,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.
Run Code Online (Sandbox Code Playgroud)

因此,根据您的情况,您可以按照以下说明调整 Exec 条目:

Exec=/usr/bin/cloudjerun -c %u
Run Code Online (Sandbox Code Playgroud)

请注意,%u 是完整的 uri,因此例如当您运行xdg-open cloudje:firefox %u 将是cloudje:firefox。我认为最简单的方法是调整 cloudjerun python 脚本,在运行之前删除 uri 的第一部分。