Add your own Services in KDE Dolphin

I wrote this for my homepage, but given how I’m not gonna start it anytime soon, I decided to post this here instead of waiting.

KDE makes it really easy do add custom file menu entries to Dolphin.

This mechanism can be quite powerful and make your life easier by putting some of your tasks under simple click.

Let’s start with going to ~/.local/share/kservices5/ServiceMenus/. This is directory in which your menu services are stored. Additionally /usr/share/kservices5/ServiceMenus/ keeps global services.

Create new file named add_date.desktop , open it in text editor and input

Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=text/plain
Actions=add_date;

[Desktop Action add_date]
Name=Add Date
Icon=bqm-add
Exec=date >> "%f"

This might be self explanatory for some people, but let’s go through this file. I’ll skip parts that need to stay the same for each service.

MimeType=text/plain – defines for which kinds of files menu entry will be available. For example image/png would make it support only png images while image/* would apply to all image types.
If you’re not sure what type given file is, you can check it with file --mime-type <path to file>
Actions=add_date; – name of our action
[Desktop Action add_date] – defines an action
Name=Add Date – name showed to the user
Icon=bqm-add – name of the system icon we’d like to use
Exec=date >> "%f" – command executed. %f is path to file on which action will be used. In this case we add current date to the end of text file.

Single service can register multiple actions. Just add them into Actions and create entry for each.

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=text/plain
Actions=add_date;hello;


[Desktop Action add_date]
Name=Add Date
Icon=bqm-add
Exec=date >> "%f"

[Desktop Action hello]
Name=Add Hello World
Icon=bqm-add
Exec=echo "Hello World" >> "%f"

Additionally, it might be good idea to group our actions into a sub-menu. To do that we need to add X-KDE-Submenu=Visible Name to a [Desktop Entry] . You might also add Icon to the sub-menu, as well as for the entries.

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=text/plain
Actions=add_date;hello;
Icon=bqm-add
X-KDE-Submenu=Add date Submenu


[Desktop Action add_date]
Name=Add Date
Icon=bqm-add
Exec=date >> "%f"

[Desktop Action hello]
Name=Add Hello World
Icon=bqm-add
Exec=echo "Hello World" >> "%f"

The result:

3 Likes

Let me know if any part of this tutorial is unclear or difficult to understand. I’ll gladly help or expand the text.