Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
Why not use Alt+Shift+Tab – Ashu May 17 '12 at 17:09
Good point, but I think maybe you mean Alt+Tab ? Alt+Shift+Tab doesn't do anything on my machine.... – Bradley Peterson May 20 '12 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 May 20 '12 at 18:24

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

#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 &
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.