You can easily create custom items for the contextual menu on Dolphin to execute scripts on files.

Create a .desktop file inside /usr/share/kservices5/ServiceMenus/ (e.g.: copyTextContent.desktop) and add this content to the file:

  • [Desktop Entry]
  • Type=Service
  • X-KDE-ServiceTypes=KonqPopupMenu/Plugin,<mimetype>: replace <mimetype> with the MIME types of the files in which you want the custom menu item appears. For example, for text files add text/*. You can add several MIME types (separated by commas).
  • Actions=<action name>: replace <action name> with a name for the desktop action (e.g.: Myaction)

  • [Desktop Action <action name>]: after a blank line, add this and replace <action name> with your chosen desktop action name.
  • Name=<item name>: replace <item name> with the name for the menu item.
  • Exec=<command>: replace <command> with the command you want to execute. To refer to the file, add %U as a command argument.
  • Icon=<icon name>: you can optionally add an icon.

This is an example (copies the content of a text file to the clipboard, requires xclip):

[Desktop Entry]

[Desktop Action Copytext]
Name=Copy Text Content
Exec=xclip -selection clipboard %U

Save the file and the menu item will appear inside Actions section in the contextual menu.

Custom menu item in Dolphin

If you have any suggestion, feel free to contact me via social media or email.