Announcement

Collapse
No announcement yet.

Launch only one instance of KCalc

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Launch only one instance of KCalc

    My keyboard has a button to launch calculator and I often use it to launch KCalc. However, if I forget that I already have KCalc running and hit that key again, I end up with two instances of KCalc. Is there a way to switch to the running instance of KCalc instead of launching a new one? I don't need to use KCalc, I am open to any other calculator app.

    #2
    xdotool can do that sort of thing. I don't have a calculator key on my keyboard, so I don't know if it can be remapped.

    But I have mapped a key to do what you want:
    1. Install xdotool using your favourite method; f.ex. muon package manager.
    2. Right-click the K-menu, select Edit applications, to start the KDE Menu Editor.
    3. In some place you find sensible, maybe Utilities, make a new item, give it a name, and for the command use
      Code:
      if ! xdotool search --classname --onlyvisible KCalc windowactivate; then kcalc;fi
    4. On the advanced tab, set up a shortcut key by clicking the button that says "None".
    5. Save the menu changes; maybe by clicking Save on the toolbar, or File->Save.

    A big caveat is that I find xdotool can be capricious, illogical or inexplicable. Another caveat is that this is using the X window system, and with Wayland I imagine there'll be problems.
    Regards, John Little

    Comment


      #3
      I use wmctrl for this purpose.

      Example: wmctrl -xa Konsole || konsole

      I too don't have a Calculator key and so don't know whether this will work ...
      Kubuntu 20.04

      Comment


        #4
        Thank you @jlittle and @chimak111
        I am using wmctrl and it works perfectly!

        Comment


          #5
          Originally posted by jlittle View Post
          A big caveat is that I find xdotool can be capricious, illogical or inexplicable. Another caveat is that this is using the X window system, and with Wayland I imagine there'll be problems.
          There's ydotool over at GitHub but it looks like the developer is facing some constraints.
          Kubuntu 20.04

          Comment

          Working...
          X