This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KDE Shortcut to launch OR select a running application

Tags: None
(comma "," separated)
nirrub
Registered Member
Posts
2
Karma
0
Hi all - new here

I'm looking to make the migration to KDE and I'd really like to know if there's an option to define a keyboard shortcut that will choose a running app or launch it if it's not running. I know how to do the latter, but I wonder if it's even possible. For reference, I'm looking to emulate Unity's behaviour when pressing Super+Num to select an app on the Dash or launch it if it's not running. The intended KDE uses Plasma 5 if it's important.

Thanks a bunch!
luebking
Karma
0
"choose" *where*?

If you mean as a global shortcut, I'd suggest a bash script - either using wmctrl (likely available from your distro) or (the far superior ;-) kwindowsystem

https://github.com/luebking/KLItools/bl ... system.cpp
(the entire KLItools tree as a build script, but it currently still links KDE4, but you'll have installed kdelibs for a while anyway)

Code: Select all
wmctrl -a xterm || xterm


resp.

Code: Select all
kwindowsystem activate xterm || xterm
nirrub
Registered Member
Posts
2
Karma
0
Thanks - exactly what I was looking for!!!
raul_l
Registered Member
Posts
20
Karma
0
If you wan't the exact Unity behavior, you might be interested in this post. The script always focuses on the last focused window of the required application, which you won't necessarily get with a simple `wmctrl -a xterm || xterm`. In addition to defining a bunch of key-bindings for frequenctly used applications, I've found it useful to have another key-binding for any app not part of the favourites. For example, the following script focuses the last focused window that was neither Firefox nor Emacs:
Code: Select all
apps="Navigator.Firefox emacs.Emacs Plasma.Plasma"

workspace=$(wmctrl -d | grep '\*' | cut -d ' ' -f1)
win_list=""
for app in $apps; do
    win=$(wmctrl -lx | grep $app | grep " $workspace " | awk '{print $1}')
    win_list+=" $win"
done

IDs=$(xprop -root|grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
IDs=(${IDs##*#})

for (( idx=${#IDs[@]}-1 ; idx>=0 ; idx-- )) ; do
    match=0
    for i in $win_list; do
   if [ $((i)) = $((IDs[idx])) ]; then
       match=$i
   fi
    done
    if [ $match = 0 ] && \
       [[ $(wmctrl -l | grep ${IDs[idx]##0x} | grep " $workspace ") ]]; then
   wmctrl -ia ${IDs[idx]}
   exit 0
    fi
done
   
exit 1


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]