Difference between revisions of "xdg-open"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(Created page with "category:software category:open-source ==About== {{fmt/quote|xdg-open is a command-line utility for opening files and URLs using the default applications as specif...")
 
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[category:open-source]]
 
[[category:open-source]]
 
==About==
 
==About==
{{fmt/quote|[[xdg-open]] is a command-line utility for opening files and URLs using the default applications as specified by the user's desktop environment.}}<ref name=chatgpt1 />
+
{{fmt/quote|[[xdg-open]] is a command-line utility for opening files and URLs using the default applications as specified by the user's desktop environment.}}<ref name=chatgpt1 /> Its current implementation (as of Ubuntu-MATE 23.10) is as a [[bash]] script which determines which desktop environment (DE) is running, and then delegates to the appropriate command for that DE. In other words, it's a slightly klugey bit of glue that deals with the lack of a standard URL-opening function across different DEs.
 
==How To==
 
==How To==
===custom protocol<ref name=chatgpt1 />===
+
* [[/how to/add custom protocol|add a custom protocol]]
'''Q:''' How can I add a custom protocol to xdg-open?
+
==Delegation==
 
+
Some of the commands to which [[xdg-open]] will delegate:
<strong>Create a custom desktop file:</strong>
+
* {{l/cmd|enlightenment_open}} (e)
* Create a new desktop file for your custom protocol. Desktop files usually have a <code>.desktop</code> extension and are located in the <code>/usr/share/applications/</code> directory or <code>~/.local/share/applications/</code> for user-specific settings.</p><p>Example (<code>custom-protocol.desktop</code>):</p>
+
* {{l/cmd|exo-open}} ([[XFCE]])
<syntaxhighlight lang=ini>
+
* {{l/cmd|gio}} open (Gnome3, [[MATE]], XFCE)
[Desktop Entry]
+
* {{l/cmd|gvfs-open}} (Gnome3, MATE, XFCE)
Name=Custom Protocol Handler
+
* {{l/cmd|kde-open}} ([[KDE]])
Exec=/path/to/your/custom-protocol-handler %U
+
* {{l/cmd|kfmclient}} (KDE)
Terminal=false
+
* {{l/cmd|gnome-open}} (Gnome)
Type=Application
+
* {{l/cmd|open_generic}} (e, Gnome, Gnome3, MATE, XFCE)
MimeType=x-scheme-handler/custom-protocol;
 
</syntaxhighlight>
 
Customize the <code>Exec</code> line to point to the executable that will handle your custom protocol.
 
* <strong>Update MIME types:</strong>
 
Open the file <code>/usr/share/applications/mimeinfo.cache</code> or <code>~/.local/share/applications/mimeinfo.cache</code> and add the following line:
 
<blockquote>
 
x-scheme-handler/custom-protocol=custom-protocol.desktop;
 
</blockquote>
 
If the <code>mimeinfo.cache</code> file doesn't exist, you may need to create it.
 
* <strong>Update the MIME database:</strong>
 
Run the following command to update the MIME database:
 
<syntaxhighlight lang=bash>
 
update-desktop-database ~/.local/share/applications/
 
</syntaxhighlight>
 
If you added the desktop file to the system-wide directory (<code>/usr/share/applications/</code>), you might need to run the command with superuser privileges:
 
<syntaxhighlight lang=bash>
 
sudo update-desktop-database /usr/share/applications/
 
</syntaxhighlight>
 
* <strong>Test your custom protocol:</strong>
 
After completing the above steps, you should be able to use <code>xdg-open</code> with your custom protocol. For example:
 
<syntaxhighlight lang=bash>
 
xdg-open custom-protocol://example
 
</syntaxhighlight>
 
This should launch the specified handler for your custom protocol.</p></li></ol><p>Remember to replace "custom-protocol" with your actual protocol name and update file paths accordingly. Additionally, depending on your desktop environment, there may be slight variations in the steps. If your desktop environment supports <code>xdg-open</code>, these general steps should work.
 
 
==Footnotes==
 
==Footnotes==
 
<references>
 
<references>
 
<ref name=chatgpt1>'''2024-01-01''' ChatGPT 3.5, in response to "How can I add a custom protocol to xdg-open?"</ref>
 
<ref name=chatgpt1>'''2024-01-01''' ChatGPT 3.5, in response to "How can I add a custom protocol to xdg-open?"</ref>
 
</references>
 
</references>

Latest revision as of 00:47, 3 January 2024

About

«xdg-open is a command-line utility for opening files and URLs using the default applications as specified by the user's desktop environment.»[1] Its current implementation (as of Ubuntu-MATE 23.10) is as a bash script which determines which desktop environment (DE) is running, and then delegates to the appropriate command for that DE. In other words, it's a slightly klugey bit of glue that deals with the lack of a standard URL-opening function across different DEs.

How To

Delegation

Some of the commands to which xdg-open will delegate:

Footnotes

  1. 2024-01-01 ChatGPT 3.5, in response to "How can I add a custom protocol to xdg-open?"