Skip to content

Opening files with flatpak apps through ranger

Ragnarov edited this page Oct 18, 2022 · 1 revision

Introduction :

Basically ranger is a terminal program.

So anyway to launch those flatpak apps has to be terminal friendly.

There are two ways to launch flatpak apps in my knowledge.

  • flatpak run org.gimp.GIMP

    This showed how to run GIMP

  • The other is to run .desktop files under /var/lib/flatpak/exports/share/applications

Here we are going to show how to utilize those .desktop files.

Cause those .desktop's are already setup correctly to open files using flatpak's command-line interface.

For this we need to use a resource opener.

There are several ways of doing this.

We will show two of them.

The programs we are going to use are:

  • gtk-launch
  • xdg-open

The reason is that these two serve different but special cases.

Using gtk-launch :

gtk-launch works as follows:

gtk-launch file.name.desktop big_buck_bunny.mkv

Following is an example using smplayer.

gtk-launch info.smplayer.SMPlayer.desktop big_buck_bunny.mkv

So one would add to their rifle.conf:

mime ^video|audio, X, flag f = gtk-launch info.smplayer.SMPlayer.desktop "$@"

Using xdg-open :

The other way to do this is:

xdg-open target_file.mp4

For this one would add to their rifle.conf:

label open, has xdg-open = xdg-open "$@"

Note: this option is already added to rifle.conf

Notice that xdg-open do not ask which .desktop file the user want to use.

It simply uses the default opener for that file.

Whereas gtk-launch needs the .desktop's name to be used for opening the file.

Conclusion :

One place where gtk-launch may be preferable is when one wants to retain

xdg-open entry yet open a file using a .desktop and ensure that a

specific application is used every time, even if someone changes default application

for that file type.

Such an arrangement is shown below :

owLD

Note: Default application associations of xdg-open for different filetypes,

can be changed using xdg-mime.

But that is out of the scope of this guide.