[SOLVED] Bring existing KDE Konsole into focus instead of launching if one exists

I use KDE on arch and would like to achieve the following behavior:

Whatever way I launch Konsole, I want it to check whether there already is a Konsole instance. If one exists, it should be brought into focus, and if no instance exists, one should be launched.

I am unable to find such an option in the Konsole settings, even though I found a roughly 1 year old forum entry mentioning such a setting. Was it removed or am I just blind? Or do I need some optional dependency?

Alternatively, it would be fine if this could simply kick in when I use my Super+K shortcut, which I’ve set up. Maybe there’s a way to call Konsole from the terminal like that? I tried using konsole --force-reuse but it didn’t seem to do the trick, and konsole --new-tab does not bring Konsole into the foreground.

Edit: Here’s a script that does this, by @Audalin


<span style="color:#323232;">#!/bin/bash
</span><span style="color:#323232;">WIN="$(kdotool search --class org.kde.konsole | head -1)"
</span><span style="color:#323232;">if [[ "$WIN" != "" ]]; then 
</span><span style="color:#323232;">    kdotool windowactivate "$WIN"
</span><span style="color:#323232;">else 
</span><span style="color:#323232;">    konsole
</span><span style="color:#323232;">fi
</span>

kdotool is available in AUR as https://aur.archlinux.org/packages/kdotool-git

Audalin,

If you don’t find such a setting, you can try writing a script that checks if it’s running already (e.g. with pgrep), activates the window if found (no idea how to do that in Wayland properly) and launches a new instance otherwise. Then use a custom .desktop launcher for Konsole.

meekah,
@meekah@lemmy.world avatar

Thanks for your reply :) I might look into it if I don’t find anything easier

Audalin, (edited )

Here’s a KDE-specific script with kdotool (Wayland always needs custom solutions for simple things):


<span style="color:#323232;">#!/bin/bash
</span><span style="color:#323232;">WIN="$(kdotool search --class org.kde.konsole | head -1)"
</span><span style="color:#323232;">if [[ "$WIN" != "" ]]; then 
</span><span style="color:#323232;">    kdotool windowactivate "$WIN"
</span><span style="color:#323232;">else 
</span><span style="color:#323232;">    konsole
</span><span style="color:#323232;">fi
</span>
meekah,
@meekah@lemmy.world avatar

sweet! thank you so much!

d3Xt3r, (edited )

deleted_by_author

  • Loading...
  • Audalin,

    Well, that’s exactly what I did. My point was rather that there’s no single consistent way to do this across different DEs with different Wayland implementations - and that’s supposedly considered a feature from Wayland design’s perspective.

    meekah,
    @meekah@lemmy.world avatar

    How have you read the part you quoted without reading the package name right in front of it?

    johsny,
    @johsny@lemmy.world avatar

    I would like to know too. Subscribed.

    meekah,
    @meekah@lemmy.world avatar

    in case you weren’t notified despite subscribing to the post, there is a solution now :)

    johsny,
    @johsny@lemmy.world avatar

    Thank you!!

    meekah,
    @meekah@lemmy.world avatar

    @mods: If I should cool it on the questions today, let me know.

    catloaf,

    I’m not a mod here, but two should be fine. Just don’t keep asking simple questions day after day or week after week. That’s when it gets annoying.

    meekah,
    @meekah@lemmy.world avatar

    Is this a simple question? It’s hard to tell from my inexperienced position. I have a few friends who are more experienced with linux than I am, and they help me out from time to time. But when they are not available and I am unable to find something on google after 15-30 minutes, I tend to start posting to forums haha

    johsny,
    @johsny@lemmy.world avatar

    Google search is so useless these days too!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.world
  • ngwrru68w68
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • InstantRegret
  • Durango
  • Youngstown
  • everett
  • slotface
  • rosin
  • cubers
  • mdbf
  • kavyap
  • GTA5RPClips
  • JUstTest
  • cisconetworking
  • osvaldo12
  • ethstaker
  • Leos
  • khanakhh
  • normalnudes
  • tester
  • modclub
  • tacticalgear
  • megavids
  • provamag3
  • anitta
  • lostlight
  • All magazines