[SOLVED] Wrong application for opening directories with xdg-open
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Wrong application for opening directories with xdg-open
Background: I'm using udiskie for automatic mounting of devices with a window manager. It is working well, except that when I try to browse a mounted volume, it opens in Firefox instead of my default file browser (PCManFM). I looked in the source code for udiskie, and it appears to use xdg-open for browsing.
I have set xdg-mime to open directories with PCManFM:
But when I try to open a directory with xdg-open, I get the following:
Code:
dan@Thinkpad-T430:~$ xdg-open ~
/usr/bin/xdg-open: line 781: x-www-browser: command not found
And then it proceeds to open the directory with Firefox. I can get around this by setting the BROWSER environment variable to pcmanfm, but why is it attempting to open directories with Firefox in the first place, if I have pcmanfm set as the default for inode/directory?
Note: I have also tried using different file managers instead of PCManFM, but the behavior is the same no matter what.
xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type.
So the problem seems to be that it interprets directories as URLs. Perhaps setting the default application for inode/directory is not the proper way to fix this, but I'm not sure what the proper way is.
I will give that a try when I get home and can install XFCE, but surely there must be a way to make this work without installing a new DE. After all, the whole point of using a window manager is that I don't want to use a DE.
I did some testing on the KDE side, and everything worked as expected. I then went back to the window manager (awesome) and set:
Code:
export XDG_CURRENT_DESKTOP=KDE
and then it worked. However, I'd rather not do that if possible, because then it must run kdeinit5 first, which seems unnecessary. I don't want to be dependent on KDE just to get XDG mime associations working correctly.
If I hard-code the desktop file in xdg-open like this:
Code:
open_generic_xdg_mime()
{
filetype="$2"
- default=`xdg-mime query default "$filetype"`
+ default="pcmanfm.desktop"
if [ -n "$default" ] ; then
xdg_user_dir="$XDG_DATA_HOME"
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
xdg_system_dirs="$XDG_DATA_DIRS"
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
search_desktop_file "$default" "$x/applications/" "$1"
done
fi
}
then it works even without XDG_CURRENT_DESKTOP set to KDE. So the question is now, is the problem with the semicolon being present in the xdg-mime query output, or is it with how xdg-open parses it? FWIW, I tried manually editing ~/.local/share/applications/mimeapps.list to add or remove the semicolon, and it didn't make a difference.
You can see all the default applications in ~/.local/share/applications/ in mimeapps.list and defaults.list.
That's where xdg gets its info from.
I'm going to have to look at the xdg-mime source code now, because this is getting confusing. When I was testing on KDE, I set the default for inode/directory to Dolphin though KDE system settings. Now I reset it to PCManFM with `xdg-mime default pcmanfm.desktop inode/directory`. There is no ~/.local/share/applications/defaults.list, but mimeapps.list shows pcmanfm.desktop as the default. However, `xdg-mime query default inode/directory` still outputs "org.kde.dolphin.desktop;", even after rebooting. So where could it be getting that from?
Last edited by montagdude; 12-19-2017 at 05:28 PM.
Well there is also /usr/share/applications but doing a locate org.kde.dolphin.desktop doesn't show anything. I would guess that it's querying kde system settings somehow.
Apparently, it was finding ~/.config/mimeapps.list, which must be the file the KDE uses. That file had a whole list of applications for inode/directory, separated by semicolons. xdg-mime doesn't handle this correctly, apparently.
The XDG_UTILS_DEBUG_LEVEL environment variable causes xdg programs to print more info, which showed that it was checking /home/dan/.config/mimeapps.list. To fix it, I did this:
EDIT: In case that's not clear, the fix was to rename ~/.config/mimeapps.list to ~/.config/mimeapps.list.bkp and then run `xdg-mime default pcmanfm.desktop inode/directory`.
Last edited by montagdude; 12-19-2017 at 08:13 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.