5

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 http://askubuntu.com/questions/20989/how-do-i-tell-a-start-up-program-to-start-minimized – 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
  • @chronitis If I configure firefox as described in you link, will it always start minimized? – Ludwig Magnusson Jul 29 '13 at 16:22
  • As far as I know, yes, it would always start minimised, regardless of whether you started it from the terminal/dash/whatever. – chronitis Jul 29 '13 at 20:25
  • @chronitis Then that is unfortunately not what I am looking for. But thanks anyway. – Ludwig Magnusson Jul 30 '13 at 06:44
  • If you are using the KDE desktop, then the kstart command allows you to start applications while also specifying KDE/QT options that control window behavior. I don't see anything that does exactly what you want, but --tosystray or --onbottom might come close. I've found it quite difficult to find good documentation on kstart. kstart --help-all > kstart.txt will get you started. – Joe Aug 01 '13 at 07:26

1 Answers1

4

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:
#!/bin/bash

delay=2
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:

    firefox.sh
    

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

Radu Rădeanu
  • 169,590
  • 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 06: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 06: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 06: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 07: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 08:51
  • @LudwigMagnusson IT IS a a linux/ubuntu specific question... I did not say otherwise. BUT MAKE YOUR QUESTION CLEAR. You can EDIT IT (and I will delete my answer) or you can ASK ANOTHER ONE. In the current state of the question is unlikely that you will get an answer for/refering to karma test runner. In the title and in the body of the qoestion you referred only the terminal. How can someone know that you expect an answer unrelated in the question??? – Radu Rădeanu Jul 31 '13 at 09:16