xdg-open vs exo-open

While playing with XFCE (more on that later) I was searching for a tool equal to gnome-open. Gnome-open can be used under Gnome to open files etc in the preferred application. While Googling I found not one, but two tools in various blogposts and forum messages: xdg-open and exo-open. I tried both, and both did the trick.
So that left me wondering: what's the difference after the two? Googling didn't really give a useful answer.
Yesterday I found the answer, by accident: exo-open is the tool from XFCE to open files etc in your preferred application, similar to gnome-open, under Gnome, and kde-open under KDE. xdg-open is a shell-script which works independent from the desktop-environment. It will inspect your environment and if it can detect that you are running Gnome, KDE, XFCE or LXDE it will use the correct tool from your Desktop Environment (such as exo-open under XFCE). If it can't detect your environment it will try to open the file itself. So basically, if you know which Desktop Environment you are running, you can use the tools which comes with your DE. If you're uncertain, or you are writing a script which should work across different Desktop Environments, use xdg-open. Or simply always use xdg-open.

Comments

Hardik's picture

Hi,

I am using xdg-open ,
so when the program runs and i tried to open that FileName.pdf using my application tries to open that file in the default browser say Firefox,rather than the Default Viewer for the .pdf files.

Any Help....

Stephan Sokolow's picture

Hardik, when xdg-open doesn't detect a KDE/GNOME/Xfce/LXDE session, it's quite stupid.

 

If you have any shell scripting experience at all, my advice would be to run sh -x $(which xdg-open) FileName.pdf to see how it's deciding to use your browser.

 

For example, on my emergency machine's Lubuntu desktop, it ignores my preference for Chromium and opens URLs in Firefox because the session name is "Lubuntu" and "Lubuntu" != "LXDE" and the generic lookup for URLs ignores ~/.local/share/applications/mimeapps.list in favor of $BROWSER (which can't be set to xdg-open and will default to preferring Firefox over Chromium if unset)

Matthew's picture

I had this problem. sh -x was helpful, and I found that xdg-open needs xprop, which wasn't available on my machine.

Add new comment