16

I have 150 Debian Jessie machines that open ODS files in Gnumeric when double-clicked despite LibreOffice Calc being installed. I know it is possible to change this by right-clicking the ODS file and changing its default program from the Properties window, but getting 150 users to do this is not an option. They all use xfce4 and thunar.

I need to do this via CLI so I can do it across all workstations remotely. I have looked in /usr/share/applications and ~/.local/share/application/mimetypes.list with no luck - comparing the files before and after changing it via GUI revealed no changes here.

How can I use bash to make these workstations open ODS files with LibreOffice Calc by default?

EDIT: Unlike the answers to this question, my Jessie installs do not have ~/.config/mimeapps.list or /usr/share/applications/defaults.list

9
  • 1
    Just as a nit-pick, you're looking for a command-line solution; it doesn't matter that your shell is bash.
    – Jeff Schaller
    Commented Mar 8, 2017 at 22:21
  • can you check if your systems have the '/usr/share/applications/defaults.list' file? What window managers/file managers are on your systems?
    – hyph
    Commented Mar 8, 2017 at 23:48
  • 1
    Possible duplicate of Set default pdf reader
    – hyph
    Commented Mar 8, 2017 at 23:49
  • @hyph I don't have a /usr/share/applications/defaults or ~/.conf/mimeapps.list. I'm using xfce and thunar. Commented Mar 9, 2017 at 14:12
  • 1
    @hyph Unfortunately my Jessie installs do not have a /usr/share/mime directory either, so that answer is not much help. Commented Mar 9, 2017 at 16:43

1 Answer 1

13

You can use mimeopen with -d option:

man mimeopen :

DESCRIPTION
   This script tries to determine the mimetype of a file and open it with
   the default desktop application. If no default application is
   configured the user is prompted with an "open with" menu in the
   terminal.


-d, --ask-default
       Let the user choose a new default program for given files.

Example:

mimeopen -d file.mp4

sample output:

Please choose a default application for files of type video/mp4

   1) VLC media player  (vlc)
   2) Other...

Verify it:

xdg-open file.mp4
5
  • 1
    This works! You can also pipe input like so: echo "2" | mimeopen -d test.ods I have just one question: Is there a way to close the window this opens via bash script? If I run this over SSH it cannot open the window on my machine (X11Forwarding is off), so it hangs waiting for it to open. I can ^C out but I'm not sure how to send that input in a script. Commented Mar 9, 2017 at 18:40
  • @user5104897 run ps aux | grep libre then run kill PID
    – GAD3R
    Commented Mar 10, 2017 at 17:29
  • I can do that manually, but how do I feed the PID to kill automatically? For example ps aux | grep libre | kill to kill all the PIDs left by the grep, or something like that. Commented Mar 10, 2017 at 17:59
  • Only the PID witch belongs to Libre Office Calc. Also you can verify the X-forwarding on the remote machine e,g: cat /etc/ssh/sshd_config | grep X11Forwarding
    – GAD3R
    Commented Mar 10, 2017 at 18:12
  • Hmm, the last step wont work for me. It runs the program fine, but does not seem to be changing the default application
    – Jonathon
    Commented Jan 20, 2023 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .