These are just some unorganized notes on freedesktop/xdg utils.
Links
- Homepage
- https://www.freedesktop.org/
- Specifications
- https://specifications.freedesktop.org/
Misc
- Look at environment variable
XDG_DATA_DIRS - Look at
~/.local/share/applications/mimeapps.listfor default application associations. - You can add
.desktopfiles to~/.local/share/applications/mimeapps.list - mime-info database possibly in
~/.local/share/mime/mime.cache -
shared-mime-info specification: https://specifications.freedesktop.org/shared-mime-info/latest-single/
Possible canonical URL: http://www.freedesktop.org/standards/shared-mime-info .desktopfile specification: https://specifications.freedesktop.org/desktop-entry/latest-single- Desktop menu specification? https://specifications.freedesktop.org/menu/latest-single/
# See how map links are opened.
xdg-settings get default-url-scheme-handler geo
# Returns something like:
# org.gnome.Maps.desktop
# Same thing as above, but alternate way
xdg-mime query default x-scheme-handler/geo
# Find .desktop applications that can handle geo: uris
gio mime x-scheme-handler/geo
# Set scheme handler (under GNOME)
gio mime x-scheme-handler/geo org.gnome.Maps.desktop
# Set scheme handler (alternate)
xdg-settings set default-url-scheme-handler geo org.gnome.Maps.desktop
# You may also need to:
xdg-mime default org.gnome.Maps.desktop x-scheme-handler/geo
# Try opening a URI:
gio open geo:37.79821,-122.41351
# From https://wiki.archlinux.org/title/Xdg-utils
# Find mime type of a particular file.
xdg-mime query filetype photo.jpeg
# Find default opener of mimetype image/jpeg
xdg-mime query default image/jpeg
# Make an array of XDG_DATA_DIRS
IFS=':' read -ra dirs <<< "${HOME}/.local/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
# Example of trying to find org.gnome.Maps.desktop definition
# Not sure if this correctly escapes things, but seems to work.
find "${dirs[@]/%//applications}" -name "org.gnome.Maps.desktop" 2>/dev/null
# List all .desktop files
find "${dirs[@]/%//applications}" -name "*.desktop" 2>/dev/null
# Find shared mime-info
find "${dirs[@]/%//applications/}" -name "mimeinfo.cache" 2>/dev/null
# Another way of filtering.
for f in "${dirs[@]/%//applications/mimeinfo.cache}"; do
[[ -f "$f" ]] && echo "$f"
done
# Also from ArchWiki.
# Debug default application from mime type
env XDG_UTILS_DEBUG_LEVEL=10 xdg-mime query default text/html
# Set URL scheme handler
xdg-mime default firefox.desktop x-scheme-handler/https x-scheme-handler/http
# See which files contain "somepattern"
find "${dirs[@]/%//applications}" -name "*.desktop" -exec grep -l "somepattern" {} + 2>/dev/null
# See the lines that contain it
find "${dirs[@]/%//applications}" -name "*.desktop" -exec grep "somepattern" {} + 2>/dev/null