Science and technology

How I exploit Ansible so as to add a characteristic to my Linux KDE desktop

I run the KDE Plasma Desktop on my laptop as a result of it is a flexible environment with numerous choices for personalisation. Having selections in your desktop is about extra than simply having numerous menus and buttons to activate or deactivate. The factor I really like most about KDE Plasma Desktop is the power so as to add my very own options to it. One cause that is potential is OkayServices, a easy however highly effective plugin framework for dealing with desktop providers.

In the KDE Plasma Desktop, there’s normally a contextual menu out there whenever you right-click on one thing, corresponding to a listing or a file. You can add gadgets to the right-click menu by creating your individual OkayService, and you do not want something greater than a rudimentary understanding of Bash to make it work.

First, create a brand new listing in your service menu:

$ mkdir -p ~/.native/share/kio/servicemenus

Add a .desktop file:

$ contact ~/.native/share/kio/servicemenus/good day.desktop

Open the good day.desktop file in a textual content editor. A .desktop file is a small configuration file utilized by the menu system of the Linux desktop. Here’s a easy OkayServices file that generates a good day.txt file within the listing you choose:

[Desktop Entry]

[Desktop Action Hello]
Name=Say good day
Exec=contact %f/good day.txt
  • The first configuration block tells your system that this .desktop file is a service moderately than, as an example, an software.

  • The MimeType tells the Plasma Desktop to solely present this motion as an possibility whenever you right-click on a folder, not a file.

  • The Actions line identifies what motion is taken when this service is activated. The identify Hello is unfair, and refers back to the subsequent configuration block, which is a Desktop Action configuration with the identify Hello.

Here’s what the following configuration block means:

  • The Desktop Action definition named Hello.

  • The values for Name and Icon seem within the right-click menu.

  • The Exec line is the command you wish to run when your service is chosen. As a easy demonstration, this .desktop file simply creates an empty file known as good day.txt within the location that you just right-clicked on (represented by the particular variable %f).

Save the .desktop file, after which make it executable:

$ chmod +x ~/.native/share/kio/servicemenus/good day.desktop

Start a brand new occasion of the Dolphin file manager and create an empty folder. Then right-click on the folder and navigate to Actions. In the Actions menu, there is a new service out there, and it is known as Say good day as a result of that is what your .desktop file has set within the Name discipline.

(Seth Kenlon, CC BY-SA 4.0)

Look within the folder after working the service to see the empty good day.txt file that is been created.


This pattern OkayService solely works on directories as a result of the .desktop file defining the service specifies the Mimetype: inode/listing. That’s what tells Dolphin to not show the service whenever you right-click on a file.

Using mimetypes, you possibly can create extremely particular providers based mostly on what sort of file system object you choose whenever you right-click. The perl-file-mimeinfo package deal gives a mimetype command, which you should use to get the mimetype of any file. Install it together with your distribution’s package deal supervisor, after which attempt it out:

$ mimetype instance.txt
instance.txt: textual content/plain
$ mimetype Photos/instance.webp
Photos/instance.webp: picture/webp


I demonstrated a easy “hello world” instance on this article, however OkayServices may be as complicated as you want them to be. The Exec line of your OkayService .desktop file can launch any software or script, and the %f variable ensures that the goal or vacation spot of no matter will get launched is what you have right-clicked on.

For my very own workflow, I used to make use of Planter to rapidly assemble a venture atmosphere. Lately, although, I’ve switched to Ansible and this OkayService:

[Desktop Entry]

[Desktop Action planter]
Name=Create venture listing
Exec=ansible-playbook /dwelling/seth/Ansible/playbooks/standard_dirs.yaml -e dir=%f

Here’s my Ansible playbook:

- hosts: localhost
    - identify: Create directories
        path: "{{ item }}"
        state: listing
        - '{{ dir }}/video'
        - '{{ dir }}/edit'
        - '{{ dir }}/audio'
        - '{{ dir }}/title'
        - '{{ dir }}/render'
        - '{{ dir }}/graphic'
        - '{{ dir }}/picture'

When I right-click on a listing and choose Create venture listing, the subdirectories I would like for media tasks are added to that listing. It’s a easy characteristic for a desktop, and just a little distinctive to a selected workflow, but it surely’s the characteristic I would like. And because of OkayServices, it is a characteristic I’ve. Try out OkayServices within the KDE Plasma Desktop for your self, and add the characteristic you need.

Most Popular

To Top