You are not logged in.
Hello, how can I change the preferred applications that xdg-open uses? For example on pdf files it will open them with firefox, I'd rather have them opened in evince.
I'm using openbox standalone and pcmanfm
Offline
Try this:
Get the registered filetype of the file (NB. I just picked a pdf file)
$ xdg-mime query filetype Documents/Stuff/Stuff.pdf
application/pdf; charset=binary
Make evince the default for opening files of type application/pdf
$ xdg-mime default evince.desktop application/pdf
Confirmation that the default took
$ xdg-mime query default application/pdf
evince.desktop
$ xdg-open Documents/Stuff/Stuff.pdf
method return sender=:1.6 -> dest=:1.27 reply_serial=2
Alternatively, if you also have gnome, kde or xfce installed then it's possible to make xdg-open use the DE's preferred applications by adding the following to, say, openbox's autostart.sh:
# Fool xdg-open's detectDE function
# Choices are: DE=kde, DE=gnome, DE=xfce
export DE="xfce"
Offline
I did the above and yes 'xdg-mime query default application/pdf' returns evince.desktop, still when I do xdg-open something.pdf I get firefox.
I mailed the developers of xdg-open and one told me that xdg-open script delegates the call to the running desktop session's utility program for launching apps - anyone knows what's that for pcmanfm?. As a fallback (no supported desktop session running) it uses $BROWSER. Actually this might not be anymore the case because this person hasn't been in the developing team for a while now (his mail was in the man page).
Anyway
renato@tosharch:~$ echo $BROWSER
renato@tosharch:~$
Offline
xdg-open is a shell script, so it can easily be examined: If $BROWSER is not set then it works through a list of known browsers.
Does the $XDG_DATA_HOME environment variable exist in your desktop session and, if it does, does the file $XDG_DATA_HOME/applications/defaults.list exist?
Edit: I don't use pcmanfm myself but doesn't it have an "open with another program" right click menu option?
Last edited by azleifel (2010-03-27 17:52:55)
Offline
Does the $XDG_DATA_HOME environment variable exist in your desktop session and, if it does, does the file $XDG_DATA_HOME/applications/defaults.list exist?
yes both exist and the last line is of defaults.list is:
application/pdf=evince.desktop
Edit: I don't use pcmanfm myself but doesn't it have an "open with another program" right click menu option?
yes it does have, and the app for pdf files is set to evince. If i double click a pdf file in pcmanfm I get evince, not firefox.
maybe I could just find out the pcmanfm command to open a file and substitute that into xdg-open. That will break with upgrades though, I was hoping for something neater
Offline
Then I don't know what's wrong. I suppose, however, that it would be possible to work through the various steps that xdg-open takes to open a file and see where it breaks. For example, if I run "xdg-open Documents/Stuff/Stuff.pdf" then this is what happens:
If the DE is neither gnome, kde nor xfce then xdg-open will set
the variable $DE to "generic" and will also check $BROWSER, setting it to
"firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:links2:links:lynx:w3m"
if it isn't set already.
If $DE is "generic" then the function open_generic will be called.
open_generic will check that the file to be opened is a file and if
it is then it will call open_generic_xdg_mime, which will do the following:
$ filetype=`xdg-mime query filetype Documents/Stuff/Stuff.pdf | sed "s/;.*//"`
$ echo $filetype
application/pdf
$ default='xdg-mime query default "$filetype"`
$ echo $default
evince.desktop
$ xdg_user_dir="$XDG_DATA_HOME"
$ xdg_system_dirs="$XDG_DATA_DIRS"
$ x=`echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`
We need to select the correct path manually at this point, so
$ echo $x
/home/david/.local/share /usr/share /usr/local/share
evince.desktop is in /usr/share/applications, so
$ x="/usr/share/"
$ file="$x/applications/$default"
$ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
bash: first_word: command not found
Oops, first_word is a function
$ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2-`"
$ echo $command
evince %U
$ command="evince"
$ command_exec=`which $command 2>/dev/null`
$ echo $command_exec
/usr/bin/evince
$ $command_exec Documents/Stuff/Stuff.pdf
** (evince:26937): WARNING **: Failed to create dbus proxy for org.gnome.SettingsDaemon: Could not get owner of name 'org.gnome.SettingsDaemon': no such name
Evince has started at this point and opened Documents/Stuff/Stuff.pdf!
Offline
perl-file-mimeinfo can, in some cases, make xdg-open behave nicer.
Last edited by Mr.Elendig (2010-03-29 15:33:23)
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline