aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Engineering
  • Software

How I Use Ansible To Add A Feature To My Linux KDE Desktop

  • aster.cloud
  • March 1, 2023
  • 3 minute read

Follow this tutorial to see how I use KService and Ansible on my Linux KDE desktop.

I run the KDE Plasma Desktop on my computer because it’s a flexible environment with lots of options for customization. Having choices in your desktop is about more than just having lots of menus and buttons to activate or deactivate. The thing I love most about KDE Plasma Desktop is the ability to add my own features to it. One reason this is possible is KServices, a simple but powerful plugin framework for handling desktop services.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Add functions to the right-click menu

In the KDE Plasma Desktop, there’s usually a contextual menu available when you right-click on something, such as a directory or a file. You can add items to the right-click menu by creating your own KService, and you don’t need anything more than a rudimentary understanding of Bash to make it work.

First, create a new directory for your service menu:

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

Add a .desktop file:

$ touch ~/.local/share/kio/servicemenus/hello.desktop

Open the hello.desktop file in a text editor. A .desktop file is a small configuration file used by the menu system of the Linux desktop. Here’s a simple KServices file that generates a hello.txt file in the directory you select:

[Desktop Entry]
Type=Service
MimeType=inode/directory;
Actions=Hello

[Desktop Action Hello]
Name=Say hello
Icon=/usr/share/icons/breeze-dark/actions/symbolic/file-library-symbolic.svg
Exec=touch %f/hello.txt
  • The first configuration block tells your system that this .desktop file is a service rather than, for instance, an application.
  • The MimeType tells the Plasma Desktop to only show this action as an option when you right-click on a folder, not a file.
  • The Actions line identifies what action is taken when this service is activated. The name Hello is arbitrary, and refers to the next configuration block, which is a Desktop Action configuration with the name Hello.

Here’s what the next configuration block means:

  • The Desktop Action definition named Hello.
  • The values for Name and Icon appear in the right-click menu.
  • The Exec line is the command you want to run when your service is selected. As a simple demonstration, this .desktop file just creates an empty file called hello.txt in the location that you right-clicked on (represented by the special variable %f).
Read More  Oracle Unshackles Stores From The Cash Wrap With Flexible POS Systems

Save the .desktop file, and then make it executable:

$ chmod +x ~/.local/share/kio/servicemenus/hello.desktop

Start a new instance 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’s a new service available, and it’s called Say hello because that’s what your .desktop file has set in the Name field.

(Seth Kenlon, CC BY-SA 4.0)

Look in the folder after running the service to see the empty hello.txt file that’s been created.

Mimetypes

This sample KService only works on directories because the .desktop file defining the service specifies the Mimetype: inode/directory. That’s what tells Dolphin not to display the service when you right-click on a file.

Using mimetypes, you can create highly specific services based on what kind of file system object you select when you right-click. The perl-file-mimeinfo package provides a mimetype command, which you can use to get the mimetype of any file. Install it with your distribution’s package manager, and then try it out:

$ mimetype example.txt
example.txt: text/plain
$ mimetype Photos/example.webp
Photos/example.webp: image/webp

Executables

I demonstrated a simple “hello world” example in this article, but KServices can be as complex as you need them to be. The Exec line of your KService .desktop file can launch any application or script, and the %f variable ensures that the target or destination of whatever gets launched is what you’ve right-clicked on.

For my own workflow, I used to use Planter to quickly construct a project environment. Lately, though, I’ve switched to Ansible and this KService:

[Desktop Entry]
Type=Service
MimeType=inode/directory;
Actions=planter

[Desktop Action planter]
Name=Create project directory
Icon=/usr/share/icons/breeze-dark/actions/symbolic/folder-new-symbolic.svg
Exec=ansible-playbook /home/seth/Ansible/playbooks/standard_dirs.yaml -e dir=%f

Here’s my Ansible playbook:

---
- hosts: localhost
  tasks:
    - name: Create directories
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
      with_items:
        - '{{ dir }}/video'
        - '{{ dir }}/edit'
        - '{{ dir }}/audio'
        - '{{ dir }}/title'
        - '{{ dir }}/render'
        - '{{ dir }}/graphic'
        - '{{ dir }}/photo'

When I right-click on a directory and select Create project directory, the subdirectories I need for media projects are added to that directory. It’s a simple feature for a desktop, and a little unique to a specific workflow, but it’s the feature I want. And thanks to KServices, it’s a feature I have. Try out KServices in the KDE Plasma Desktop for yourself, and add the feature you want.

Read More  Easy Deployment Of MEAN Stack W/ MongoDB Atlas, Cloud Run, And Hashicorp Terraform

Source: Cyberpogo


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster.cloud

Related Topics
  • Ansible
  • KService
  • Linux
  • Opensource
  • Tutorials
You May Also Like
View Post
  • Engineering

Just make it scale: An Aurora DSQL story

  • May 29, 2025
View Post
  • Software
  • Technology

Canonical Releases Ubuntu 25.04 Plucky Puffin

  • April 17, 2025
View Post
  • Software
  • Technology

IBM Accelerates Momentum in the as a Service Space with Growing Portfolio of Tools Simplifying Infrastructure Management

  • March 27, 2025
View Post
  • Engineering
  • Technology

Guide: Our top four AI Hypercomputer use cases, reference architectures and tutorials

  • March 9, 2025
View Post
  • Computing
  • Engineering

Why a decades old architecture decision is impeding the power of AI computing

  • February 19, 2025
View Post
  • Engineering
  • Software Engineering

This Month in Julia World

  • January 17, 2025
View Post
  • Engineering
  • Software Engineering

Google Summer of Code 2025 is here!

  • January 17, 2025
View Post
  • Data
  • Engineering

Hiding in Plain Site: Attackers Sneaking Malware into Images on Websites

  • January 16, 2025

Stay Connected!
LATEST
  • 1
    Just make it scale: An Aurora DSQL story
    • May 29, 2025
  • 2
    Reliance on US tech providers is making IT leaders skittish
    • May 28, 2025
  • Examine the 4 types of edge computing, with examples
    • May 28, 2025
  • AI and private cloud: 2 lessons from Dell Tech World 2025
    • May 28, 2025
  • 5
    TD Synnex named as UK distributor for Cohesity
    • May 28, 2025
  • Weigh these 6 enterprise advantages of storage as a service
    • May 28, 2025
  • 7
    Broadcom’s ‘harsh’ VMware contracts are costing customers up to 1,500% more
    • May 28, 2025
  • 8
    Pulsant targets partner diversity with new IaaS solution
    • May 23, 2025
  • 9
    Growing AI workloads are causing hybrid cloud headaches
    • May 23, 2025
  • Gemma 3n 10
    Announcing Gemma 3n preview: powerful, efficient, mobile-first AI
    • May 22, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • Understand how Windows Server 2025 PAYG licensing works
    • May 20, 2025
  • By the numbers: How upskilling fills the IT skills gap
    • May 21, 2025
  • 3
    Cloud adoption isn’t all it’s cut out to be as enterprises report growing dissatisfaction
    • May 15, 2025
  • 4
    Hybrid cloud is complicated – Red Hat’s new AI assistant wants to solve that
    • May 20, 2025
  • 5
    Google is getting serious on cloud sovereignty
    • May 22, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.