Currently what happens:

I press Calculator button on my keyboard, and calculator pops up. No problem there! Next, after my calculation, I click back to the window where I'm inputting the calculation, and when I press the calculator button again, a NEW window opens in the calculator program.

What I want to happen:

When I click the calculator button, it switches back to the calculator program if it's already open, else, open calculator program. I don't want it to open a new window every time I try to change back to my recent calculation.

It's not a big deal, obviously, just a slight annoyance to me so far. Is there a setting, or some terminal command I can run, or anything I can do to change it?


  • Why not use Alt+Shift+Tab
    – Ashu
    Commented May 17, 2012 at 17:09
  • Good point, but I think maybe you mean Alt+Tab ? Alt+Shift+Tab doesn't do anything on my machine.... Commented May 20, 2012 at 18:21
  • on my machine Alt+Shift+Tab lets me shift between windows(im on 10.10). maybe for you it might be Alt+Tab
    – Ashu
    Commented May 20, 2012 at 18:24

2 Answers 2


The tiny script below will do what you want. You need to install wmctrl for it to work:

sudo apt-get install wmctrl

After you've installed wmctrl, paste the text below into a file and call it whatever you want. I called mine calc-activate.sh.

#This script switches focus to gnome-calculator if it is running.
#If it is not running, it will run gnome-calculator.

if [ "$(wmctrl -l | grep Calculator)" != "" ]; then
    wmctrl -a "Calculator"
    gnome-calculator &

After saving, the text file, make it executable either by right clicking and going to the permissions tab and checking off the Execute boxes, or do it from the terminal with the chmod command).

Now you can set your multimedia keys:

  • For Ubuntu 11.10 and earlier, go to: SystemPreferencesKeyboard Shortcuts
  • For 12.04 and later, hit the Super key, type "shortcut" then hit Enter.
  • Now find the "Launch calculator" shortcut, click on it and hit backspace to disable it.
  • Now you can add a new custom shortcut. Point the command to the full path of the script you just saved. Click on the new command and press the calculator button to assign it. Voila!

Please note: Since wmctrl looks for a program titled "Calculator" the above script snippet might not work with other languages. To fix, change Calculator so it matches the window title of gnome-calculator.

Danish example:

if [ "$(wmctrl -l | grep Lommeregner)" != "" ]; then
    wmctrl -a "Lommeregner"
    gnome-calculator &
  • 2
    Great tip - still using this and works over 8 years later! I've made a tiny alteration - it was opening this browser window as Calculator was in the title. The following code stops that from happening: wmctrl -F -a Calculator; if [ $? -eq 1 ]; then gnome-calculator &; fi Commented Jun 26, 2019 at 12:32
  • I suggested an update to the answer based on @wayfarer_boy's useful improvement
    – mmaluff
    Commented Jul 14, 2020 at 6:24
  • The script is awesome, but it's not being called for my calculator button (Fn+F4). Commented Oct 9, 2023 at 9:06

If you are using the "Microsoft keyboard and mouse" program, uninstall it and install intellitype and intellimouse from Microsoft.
I use a microsoft 5000 keyboard and mouse and recently installed MS K&M. Every time I pressed the calculator button it would open a new calculator. Intellitype will allow calculator to re-focus on the one that is open.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .