Set custom command to open certain types of files with

You know how you can right click a file > Open With > Set Default Application > use a custom command: ?

Well, I can’t seem to make it work with a program that doesn’t have a .desktop file

If I go to some .desktop file in /usr/share/applications/ , it will have a line inside such as Exec=featherpad %U

It is my understanding that %F is for multiple files, and %U is for one file to pass to the program.

OK

But when I write someprogram %U in the custom command, nothing happens.

writing someprogram filename.txt in the terminal works like a charm every time.

Would be nice to also be able to write some arguments to the program like someprogram --banana %U

Or at least. At least just invoke the equivalent of writing the command in the terminal like echo "someprogram --banana %U"

I NEED 2 THINGS:

  1. TO AUTOMATICALLY USE THIS COMMAND WHEN I DOUBLE CLICK ON A CERTAIN TYPE OF FILE
  2. FOR THUNAR OR SOMETHING TO PASS THE PATH TO THE FILE WHERE I WROTE %U

that’s it.

NOTICE: My program is in $PATH, and doesn’t have a .desktop file.

Please help!

Please see → [root tip] [How To] Create Thunar Custom Actions

Did you check, in the settings - default apps, others, if you can find the filetype? If yes, clicking on the app associated with it will bring a menu. If you see your app click it and voila.

If not, you can either edit the mimeapps.list in the ~/.config directory, or you can create a desktop file yourself.
Here are 2 examples of desktop files:

[Desktop Entry]
Version=1.0
Name=Weasis
Comment=Medical DICOM viewer
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=Weasis --file-forwarding io.github.nroduit.Weasis @@u %U @@
Icon=io.github.nroduit.Weasis
Terminal=false
Type=Application
Categories=Viewer;MedicalSoftware;Graphics;
MimeType=application/dicom;x-scheme-handler/weasis;
X-Flatpak=io.github.nroduit.Weasis
[Desktop Entry]
Version=1.1
Type=Application
Name=kfind
Icon=org.kde.kfind
Exec=kfind
Actions=
Categories=Utility;X-XFCE;X-Xfce-Toplevel;

Important is the mimetype row.
After that, put the file in the ~/.local/share/applications/
And run sudo update-desktop-database

And then in case there are now many apps for that mimetype you can select the default from the settings - default applications.

The Exec key | Desktop Entry Specification

Code Description
%f A single file name (including the path), even if multiple files are selected. The system reading the desktop entry should recognize that the program in question cannot handle multiple file arguments, and it should probably spawn and execute multiple copies of a program for each selected file if the program is not able to handle additional file arguments. If files are not on the local file system (i.e. are on HTTP or FTP locations), the files will be copied to the local file system and %f will be expanded to point at the temporary file. Used for programs that do not understand the URL syntax.
%F A list of files. Use for apps that can open several local files at once. Each file is passed as a separate argument to the executable program.
%u A single URL. Local files may either be passed as file: URLs or as file path.
%U A list of URLs. Each URL is passed as a separate argument to the executable program. Local files may either be passed as file: URLs or as file path.

xfce:exo:desktop-item-edit [Xfce Docs]

xfce:thunar:working-with-files-and-folders [Xfce Docs]

xfce:xfce4-settings:preferred-apps [Xfce Docs]

4 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.