xdg-open
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]
How To
custom protocol[1]
Q: How can I add a custom protocol to xdg-open?
These instructions have not yet been verified.
Create a custom desktop file:
- Create a new desktop file for your custom protocol. Desktop files usually have a
.desktop
extension and are located in the/usr/share/applications/
directory or~/.local/share/applications/
for user-specific settings.Example (
custom-protocol.desktop
):
[Desktop Entry]
Name=Custom Protocol Handler
Exec=/path/to/your/custom-protocol-handler %U
Terminal=false
Type=Application
MimeType=x-scheme-handler/custom-protocol;
Customize the Exec
line to point to the executable that will handle your custom protocol.
- Update MIME types:
Open the file /usr/share/applications/mimeinfo.cache
or ~/.local/share/applications/mimeinfo.cache
and add the following line:
x-scheme-handler/custom-protocol=custom-protocol.desktop;
If the mimeinfo.cache
file doesn't exist, you may need to create it.
- Update the MIME database:
Run the following command to update the MIME database:
update-desktop-database ~/.local/share/applications/
If you added the desktop file to the system-wide directory (/usr/share/applications/
), you might need to run the command with superuser privileges:
sudo update-desktop-database /usr/share/applications/
- Test your custom protocol:
After completing the above steps, you should be able to use xdg-open
with your custom protocol. For example:
xdg-open custom-protocol://example
This should launch the specified handler for your custom protocol.
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 xdg-open
, these general steps should work.