How do end-users open files with a flatpak App from command line?

Hello all Flathub enthusiasts :slight_smile:

After a flatpak App is published on Flathub. How do end-users open files with this flatpak App from command line? Assuming an App that support open file of course.

For example, this App at https://flathub.org/apps/org.kde.kwrite

For Debian 12 Bookworm, I’m guessing this command below?

/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=kwrite --file-forwarding org.kde.kwrite @@u "/<ABSOLUTE PATH TO FILE>/<FILE NAME>.txt" @@

Or this?

/usr/bin/flatpak run --file-forwarding org.kde.kwrite @@u "/<ABSOLUTE PATH TO FILE>/<FILE NAME>.txt" @@

Or what other format is appropriate?

I searched https://docs.flatpak.org but found no full answer. I found a mention of --file-forwarding, @@u, and @@ at https://docs.flatpak.org/en/latest/flatpak-command-reference.html

Those commands are equivalent in practice. flatpak-generated desktop entries are more verbose than strictly necessary. You should use @@ @@ rather than @@u @@ when using a path rather than a URI:

flatpak run --file-forwarding org.kde.kwrite @@ "/<ABSOLUTE PATH TO FILE>/<FILE NAME>.txt" @@

(I don’t think the path needs to be absolute, btw)

I typically use gio open (or xdg-open). This can only open the file with the default handler, so it won’t work for a file where you could edit or view it using separate apps, but it’s usually good enough. It uses the desktop entry, so file forwarding happens automatically.

1 Like

here’s a little script i cooked up to run flatpaks from the command line. sorry, it’s in php :confused: but it works.
https://pianocheetah.app/linux/fp2sh.html