I want to talk about DBus and how much simplify the scripting in Linux.
DBus is an inter-process communication protocol for processes, used to communicate with the already running process to change their behavior.
You are probably wondering why you should need it but is very simple. Think about the button of your keyboard to change the song of your player. This use DBus to find the used player and sending a command to change the song.
This feature is so useful that I scripted it to remove the file that I am listening and move to the next song or to change the folder of the file that I am listening.
The basic feature is to associate custom hotkeys to control the player like in VLC.
So after all DBus is very cool because is already used internally in Linux between a lot of process and you don’t know it!
To investigate it you can use
qdbusviewer inside the
qttools5-dev-tools to see all the running process what DBus sessions and service (and methods) are exposing.
This article start from a pull request that I did to a software that I am using since a lot of time, ReText. It is a simple markdown editor with a lot of features that was missing a simple feature.
The skill to not launch a new instance for every new file opened when the editor is executed. Like when you start the program by the file manager, and after few seconds a new one.
In those cases DBus is very handy because let you to expose a method
openFile and the same software will include a listener that will act based on the method requested.
In my case was quite simple, create a listener that when called will open a new tab in ReText for the new document and later also that when the software is called again will do a call to DBus and kill the process.
After 30 minutes of studying in PyQt how was it possible with demo I did a pull request to the editor.
So I used
qdbusviewer to test my listener before proceed further.
It was simple (Qt is very a big and easy framework after all) but in this way I closed a long time asked feature. That for me was very disturbing.
Anyway after using a lot DBus, it was to implement it 😀