Unity-style window activation in KDE

I have used unity in Ubuntu for a long time and i’m very used to use Win+[number] key combination to switch to windows. For example i have Win+1 to switch to terminal emulator.

Some months ago I have tried new KDE5 and it was awesome. But I found no way to activate (or launch if not started) application on shortcut :) Only lunch a new one every time, but it’s not what i want.

After 2 minutes of googling I found wmctrl utility (exist in universe repository) and 2 more minutes for scripting give me something like this:



if [ `wmctrl -l -p | grep \`pgrep $app\` | wc -l` != 0 ]
  wmctrl -i -a `wmctrl -l -p | grep \`pgrep $app\` | awk '{ print $1; }'`
  $app &

Using pgrep is needed because of konsole sets windows title to current path or host and wmctrl can’t find it by title.

After setting up shortcut in ‘system-settings’ to my favorites like konsole, qtcreator i’m really happy now 😀