If I open a program, like Firefox, from the terminal then that program will get the focus of the GUI. Can I somehow open it so that it will run in the visual background and not pop up, blocking any current program I am working with?

My problem is that I use karma test runner which is run every time I edit my code. Whenever that is done karma launches a browser which pops up in front of everything else on the screen which can be quite annoying.

I am using Ubuntu 13.04.

  • No. The program still opens up and is placed in front of the terminal. – Ludwig Magnusson Jul 29 '13 at 12:44
  • Aha, now is clear. – Radu Rădeanu Jul 29 '13 at 12:45
  • It's a bit of an anvil to crack a nut, but devilspie lets you set up rules to be applied to newly opened windows, such as sending them to specific workspaces or minimising them. See askubuntu.com/questions/20989/… – chronitis Jul 29 '13 at 15:31
  • In cairo-dock you can adjust the behaviour of programs/windows, if they should stay in background or open in front of all others. But currently with update to gnome 3.8 - cairo-dock is somewhat not entirely supported any more - due to some fixes to be done in compiz. – dschinn1001 Jul 29 '13 at 16:17

To do this, you will need xdotool. To install it, run the following command in terminal:

sudo apt-get install xdotool

Now, I will explain how you can do it for Firefox using a script:

  • In a terminal run:

    mkdir -p bin

    This command will make a bin directory in your home folder if you don't already have it.

  • After run:

    gedit ~/bin/firefox.sh

    This will create the new file change_sources.sh in gedit.

  • Copy and paste the following script in the new created file:

windowId=$(xdotool getwindowfocus)

firefox &
sleep $delay

xdotool windowactivate $windowId
  • Save the file and close it.
  • Go back into terminal and run:

    chmod +x ~/bin/firefox.sh

    to grant execute access for the script.

  • Run the script with:


In the same manner you can open any other application from terminal in the background.

|improve this answer|||||
  • I tried your solution and it works as you describe. Unfortunately it does not help me where I need it. I have another program (karma test runner) launching firefox and navigating to specific pages and karma cannot get control over firefox using this solution. – Ludwig Magnusson Jul 30 '13 at 6:47
  • @LudwigMagnusson Well, you said with your own words: "Can I start a program from the terminal...". Now you should edit your question and I will delete my answer or you can ask another question. – Radu Rădeanu Jul 30 '13 at 6:49
  • Yes I agree. I was unclear about the motives. And I gave you +1 for the solution. But using a third party program means that it does have some side effects which makes it not entirely equivalent to starting it from the terminal only changing the fact of where the window is placed. – Ludwig Magnusson Jul 30 '13 at 6:56
  • @LudwigMagnusson Ok, but you should understand that in the current state of the question is unlikely that you will get an answer for karma test runner. For example I will not expect ever an answer refering to cmd from Windows when I asked something about gnome-terminal. So, don't esitate to ask another question. – Radu Rădeanu Jul 31 '13 at 7:46
  • But I am quite sure that what I want is beyond the scope of Karma. It is a linux/ubuntu specific question since what karma does is open an application using a command that I specify. I could be wrong but from my point of view, I tried to solve my problem through terminal commands and in the process learn more about ubuntu. – Ludwig Magnusson Jul 31 '13 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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