I’m writing a GTK+ application. At the end of the program’s running, it opens the user selected directory. Currently, it is hard-coded to open nautilus:
g_spawn_sync(
0,
stringArray(
"/usr/bin/nautilus",
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(directoryChooser)),
NULL
), 0, 0, 0, 0, 0, 0, 0, 0);
gtk_main_quit();
I want this to work on other desktop environments where nautilus isn’t necessarily installed or preferred. There are links to other programs in /etc/alternatives and links such as x-terminal-emulator and x-www-browser that are standardised.
Are there similar ways to get the preferred graphical file manager?
gnome-openwill open a directory in the preferred file manager if you give it a directory name. It will also open up other preferred applications, such as a PDF viewer or broswer depending on what you pass it.Another alternative is
xdg-open, which does a similar thing.