3

I was trying to open an Excel file with python on Linux using xdg-open but realized xdg-open doesn't really work on my machine:

$ xdg-open ~/Documents/foo.xlsx 
/usr/bin/xdg-open: line 881: www-browser: command not found
/usr/bin/xdg-open: line 881: links2: command not found
/usr/bin/xdg-open: line 881: elinks: command not found
/usr/bin/xdg-open: line 881: links: command not found
/usr/bin/xdg-open: line 881: lynx: command not found
/usr/bin/xdg-open: line 881: w3m: command not found
xdg-open: no method available for opening '/home/alex/Documents/foo.xlsx'

However, the MIME type appears to be properly set up:

$ xdg-mime query default $(xdg-mime query filetype ~/Documents/foo.xlsx)
libreoffice-calc.desktop

I can also open the file fine from file manager. From the error message above it looks like xdg-open thinks it's a URL and tries to pen it with a browser.

Do I need to configure xdg for xdg-open to work?

2
  • Ignore my last comment - I totally spaced on what you were actually trying to do. I just ran a test on my system and my LO spreadsheet was opened by a text editor (which I did select once in the File Manager to open a .cvs file, but not an .ods file). – ajgringo619 Jan 15 '20 at 21:28
  • It turned out xdg-open wasn't working because XDG_CURRENT_DESKTOP variable wasn't set. And it only wasn't set in that specific shell I was using. Opening a new shell resolved the problem. What exactly unset XDG_CURRENT_DESKTOP in that shell remains a mystery. – BlindDriver Jan 16 '20 at 20:50
0

I finally got this working. I had to force a default in $HOME/.config/mimetypes and now xdg-open filename.ods works as expected:

xdg-mime default libreoffice-calc.desktop 'application/vnd.oasis.opendocument.spreadsheet'

So in your case, this should work for Excel files:

xdg-mime default libreoffice-calc.desktop 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.