0

Is there a way to open the "Open with" dialog programmatically for a given file? I mean the dialog that you get when you right-click a file in Nautilus and select "Open with".

I'm preferably looking for a simple shell command to use, but an API or a DBUS interface would also work. I'm stuck with GNOME 2.28.2 on this PC, but would be also interested in a solution for recent GNOME. Maybe there is even a standardized solution for multiple Linux-ish desktops (something like xdg-open-as)?

I tried gnome-open and xdg-open, but both just use the standard association and don't let me choose the application.

jdm
  • 9,470
  • 12
  • 58
  • 110

2 Answers2

0

I am unsure I understand your question.

If you want that a particular application appears in the "Open with" menu, then you have to register the MIME type for that application with xdg-mime, and then Nautilus will show it.

If you want a menu similar to "Open with" that opens only for specific files, then you should write a Nautilus Extension (for example, in Python or C). In the extension's code, you can check things like MIME Type, if selection is multiple, etc. Nautilus provides access to that information. See How to create nautilus C extensions

If you mean something different, then please rephrase your question :-)

gpoo
  • 8,408
  • 3
  • 38
  • 53
  • 2
    If you right click on a file, and select "Open With/Other Application...", a dialog opens. I don't want to change that dialog, but I want to open that exact same dialog from the command line (or some other program). – jdm Feb 10 '16 at 16:37
0

I could not find a command line tool like that either, so I made one. Surprisingly it is really trivial.

https://github.com/timgott/gtk-open-with

If you want to do this programatically in Gtk, it requires only few lines of code (example using the C++ bindings):

auto dialog = Gtk::AppChooserDialog(file);
int response = dialog.run();
if (response == Gtk::RESPONSE_OK)
    dialog.get_app_info()->launch(file);
timgo
  • 345
  • 3
  • 6