Files
osr-mono/packages/osr-code-bot/kbot-extensions/docs/shell-ext/ubuntu.md
T
2025-02-01 14:25:34 +01:00

2.0 KiB

Custom "Open With" Menu Integration in Ubuntu

Method 1: Using .desktop Files

To add a custom application to the "Open With" context menu, you can create a .desktop file.

  1. Create a .desktop file in ~/.local/share/applications or /usr/share/applications:
# Example: CustomEditor.desktop
[Desktop Entry]
Version=1.0
Name=Custom Editor
Comment=Open files with my custom editor
Exec=/usr/local/bin/my-editor %f
Icon=/usr/share/icons/my-editor.png
Terminal=false
Type=Application
MimeType=text/plain;text/markdown;
Categories=Utility;TextEditor;

Method 2: Using XDG Mime Database

You can also modify the XDG MIME database to associate file types with your application:

# Update the MIME by association
xdg-mime --default-apps my-editor.desktop text/plain

# Update the database
update-desktop-database

Method 3: Using Filemanager Actions (Nautilus)

You can add custom actions to Nautilus by creating a script in ~/.local/share/nautilus/scripts:

#!/bin/bash
# Save this as ~/.local/share/nautilus/scripts/custom-opener

for f in "$@"; do
    my-editor "$f"
done

Make the script executable:

chmod +x ~/.local/share/nautilus/scripts/custom-opener

Method 4: mimeapps.list Configuration

You can modify the ~/.config/mimeapps.list file:

# Add lines like this:
text/plain=my-editor.desktop;vim.desktop;gedit.desktop

Key File Locations

  • System-wide applications: /usr/share/applications
  • User-specific applications: ~/.local/share/applications
  • MIME type definitions: /usr/share/mime/packages
  • User-specific MIME overrides: ~/.config/mimeapps.list
  • Nautilus scripts: ~/.local/share/nautilus/scripts

Important Notes

  1. After making changes, you may need to:

    • Run update-desktop-database
    • Log out and back in
    • Restart Nautilus with killall nautilus
  2. For .desktop files, make sure:

    • The file has execute permissions (u+x)
    • The Exec path is correct
    • The MimeType list is appropriate for your application