How to setup custom command to run it anytime for a selected file via GUI?

Hello,

for example i want to run: recode ms-ee “pathtofile”
and i would like to execute this via gui without the need to open terminal and waste time copying, typing. Somehow for example Right click file / submenu / and “run recode” or something like that and it will run the custom command with custom parameters for the selected file.

Currently i am using XFCE and Dolphin file manager.

Hello,

A couple of resources to consider

In case you want to experiment with other file managers

2 Likes

Thank you, so i setup new service file recode.desktop in $ find ~/ -type d -name ServiceMenus
/home/me/.local/share/kservices5/ServiceMenus:

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=text/*
Actions=act

[Desktop Action act]
Name=Recode to UTF-8
Icon=document-cleanup
Exec=recode ms-ee %U

but it shows the right click menu item only when i click normal text file, not when i click file like:

$ file --mime-type ~/Downloads/*.srt
/home/me/Downloads/abc.srt: text/plain

When i set the recode.desktop file to text/plain instead of text/* then it started showing the menu.
But the file is not recoded after i click the menu entry, like the command is not executed. So i am wondering how to debug this.
UPDATE: when i launch $ dolphin from command line, and right click the file, it add line:
Cannot initialize model with data QJsonObject() . missing: QJsonValue(string, “urls”)
when i click my custom menu entry it says:
/usr/bin/recode: Request `win-ee’ is erroneous

yes, in previous file version i have used erroneous parameter, but my current file has correct one: ms-ee
So do i have to restart something? I am launching Dolphin a new to test.

Try

Exec = sh -c "recode ms-ee %U"

thank you all, @badbodh Your command may be useful for more complex commands as i read in tutorial. Thank you all for replies as it motivated me to find the solution. What helped to solve the issue is following workaround (other ways to solve are welcome if you share):

mv recode.desktop recode2.desktop
dolphin
…exit dolphin…
mv recode2.desktop recode.desktop
set the exec line like this inside the file:
Exec=recode ms-ee “%U”
(the quotation marks was important as the file can contain spaces etc.)

and all works now. I am curious if i can group my custom actions into some sub menu now.
update, yes i just need to add new line below [Desktop Entry] line to the .desktop file:

X-KDE-Submenu=Menu name here
1 Like