[gtk] opening default program for a folder

I have successfully been using g_app_info_launch_default_for_uri to open a default program for a file, but what if I want to open the default file browser at some folder? - I cannot use g_app_info_launch_default for this, right? What is the proper way to do this?

For me (I’m on a customized Xfce), I would want caja, but for a user of default Xfce I would expect Thunar.

How would I go about getting this?

You can definitely use g_app_info_launch_default_for_uri(), using a file:///path/to/directory. File managers typically install a handler for the inode/directory MIME type precisely for this reason.

1 Like

Thanks! It failed for me, since I forgot to include the “file://”. Doing that it works. Thanks! Though, standard files would work even without it, but folders not, that is what caused my confusion.

In danger of stating the obvious, _for_uri expects a URI not path — an admittedly subtle but quite important difference that, sooner or later, will probably trip you up if you try and use them interchangeably

GFile can help you out here, though surprisingly we don’t seem to have a regular _launch_default that accepts one, but it does give you an easy way to convert between paths and URIs

1 Like

Thanks - It doesn’t look like the code I put together will be used after all, but I have indeed learned something. Much appreciated!