@readwithai - X - blog - Learn FFmpeg through examples
I used to be a user of tiling window managers. They are good and all, easy-to-configure, fit within the UNIX philosopher. But they can also be a pain, you end up having to use a keyboard for stuff. Desktop environments at their best make things easier, especially when using a mouse, and using a mouse and not having to “control” everything all the time can be relaxing. It’s odd - I will literally see myself going through short periods where everything has to be done efficiently with the keyboard and then a while later I will happily click away at stuff. It probably varies depending on what I’m doing.
For this reason, as well as a feeling that I don’t want to spend too much time updating my desktop I’ve opted for to use KDE. KDE is nice and easy to use but its got some tiling-window-manager-lite features with keybindings and the ability to define your own keybindings to do most of the things you want.
And yet.
The more I use something the more the day-to-day papercuts stuff to build up - and using all these GUI configuration tools with the continuous click-click-click can get annoying. Sure it’s easier first time around - well apart from the annoyance of having to find things. But it quickly gets annoying. I don’t quite know why I find clicking through dialogs so annoying at times - while editing files is easier. I think it is something related to it being hard to find things - whereas in text files you have search and you can’t “save your place” in the same way that you can be programming or editing text files.
And so today I have learned how to set up keyboard shortcuts from the command-line with KDE and I will share this with you.
How shortcuts work in KDE
KDE has a file called ~/.config/kglobalshortcutsrc which contains all your shortcuts. Each shortcuts runs a desktop file these can either live in /usr/share/applications or more likely ~/.local/share/applications. The KDE shortcut setting tool will create these desktop files for you when you create command shortcut as well an entry in kglobalshortcutsrc.
Here is an example .desktop file that KDE created in ~/.local/share/applications called focus-obsidian.desktop which I use to raise and cycle through windows for the note-taking app, Obsidian:
[Desktop Entry]
Exec=/home/alex/bins/windows/focus-obsidian
Name=/home/alex/bins/windows/focus-obsidian
NoDisplay=true
StartupNotify=false
Type=Application
X-KDE-GlobalAccel-CommandShortcut=true
Note the NoDisplay=true which prevents the normal launcher from showing this entry. The X-KDE-GlobalAccel-CommandShortcut=true which says that this entry is for a command. There is then an entry in ~/.config/kglobalshortcutsrc which looks like so:
[focus-obsidian.desktop]
_k_friendly_name=focus-obsidian
_launch=Meta+Shift+N,none,/home/alex/bins/windows/focus-obsidian
Notice that the name of the entry matches the name of the file.
The file gets read by a process called kglobalaccel5
Creating shortcuts by hand
From this, to create a shortcut by hand we need to:
Create a desktop file
Update kglobalshortcutsrc
Restart the shortcut daemon
To create the desktop file I normally copy and adapt an existing file. If you remove the X-KDE-GlobalAccel-CommandShortcut=true the shortcut still works but it is shown as program rather than a command in the shortcut settings.
Let’s do this now. We’ll create a shortcut that says “hello world” with zenity - you may have to install zenity first.
First I add the file hello-world.desktop to the directory /home/alex/.local/share/applications
[Desktop Entry]
Exec=zenity --info --text "hello world"
Name=Hello World
NoDisplay=true
StartupNotify=false
Type=Application
Here I have removed the X-KDE-GlobalAccel-CommandShortcut option. This means, I believe, that the item is shown as a “program” in the shortcuts preferences dialog and KDE does not attempted to update the Name or Exec options.
Then I edit ~/.config/kglobalshortcutsrc to add an entry for this desktop file.
[hello-world.desktop]
_k_friendly_name=Say hello world
_launch=Meta+Ctrl+H,none,This command will say hello
Then I restart kglobalaccel5 . Unfortunately it seems like this kde daemon does not restart when you kill it, show must be restarted by hand.
I use the following command to restart kglobalaccel: killall kglobalaccel5; sleep 1; kglobalaccel5&; disown
I can then use Super+Ctrl+H and see a hello world window pop up. (Note that KDE calls the windows/super key Meta - which is a little confusing since Emacs calls the alt key meta).
You will notice if you open ~/.config/kglobalshortcutsrc that KDE tries to clean up the file on restart. It will reorder entries so that they are in alphabetically order. And add keys that you miss. If you open the settings for shortcuts you will see an entry under programs. The “friendly name” is added to the menu
The third entry of the _launch item in kglobalshortcutsrc is displayed within the details of the shortcut. This key can naturally be longer and provide more details.
Some closing thoughts
This scratches my itch of avoiding clicking too when creating keyboard shortcuts. It’s also a little-bit neater. One downside is that the KDE shortcut settings dialog would have detected collisions between shortcuts. So I need to to do this by hand.
If this is the sort of stuff you find interesting your could:
Check out my beginner’s guide to FFmpeg through examples that you can run. It’s got 50-or-so stars on Github in a couple of weeks, so people seem to like it.
Follow me on X where I post about this sort of stuff and other things.
If you like the cut of my jib you might like to check out my blog where I am working on tools for research, reading and agency with the Obsidian note taking tool.