1

A big part of my workflow is based on using shortcuts. Currently I use xbindkeys and wmctrl to run-or-raise an application. E.g: Super+F brings up firefox or run it if not running.

Autokey works fine with KDE and I could also use KDE native custom shortcut manager to replace xbindkeys but I can't find (and I googled a lot) a way to determine if a window/application is running and if not, raise it.

I can probably use ps or a similar command to find if an application is running and if not, launch it, but it goes to the final problem: how to raise (or focus) an existing running window/application programmatically?

There seems to be some kind of gdbus solution for GNOME but of course this won't work in KDE.

Does anyone have an idea or clue of what can I do?

1

After much research I got into a solution that will only work for KDE and only KDE: using a kwin script.

The script is:

  • use pgrep to see if a program is running (use full command grep)
  • if running:
    • install an on-the-fly kwin script that will explicitly "activate" a window with a passed className or title
    • run the script
    • stop the script
    • uninstall the script
  • if not running: run a command to start it.

For example, let's say I want to focus or launch firefox, I'd do with my script:

ww -f firefox -c firefox

-f: the window classname -c: the command to run if not running -fa: alternative filter to use the window title instead of the class

This is the script I am using now and it's been working great:

https://gist.github.com/academo/613c8e2caf970fabd260cfd12820bde3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.