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

I asked a related, but more specific, question here. I want to know if there is a way to specify where you want a program to launch. I basically want to write a shell script which is launched every time I log in, like so

google-chrome    -workspace=1 -monitor=1
google-chrome -workspace=1 -monitor=2
google-chrome  -workspace=1 -monitor=3

gedit a.txt b.txt c.txt        -workspace=2 -monitor=1
gedit d.txt e.txt f.txt        -workspace=2 -monitor=2
gedit g.txt h.txt i.txt        -workspace=2 -monitor=3

mplayer Terminator1.mkv        -workspace=3 -monitor=1
mplayer Terminator2.mkv        -workspace=3 -monitor=2
mplayer Terminator3.mkv        -workspace=3 -monitor=3

there is a program called wmctrl but it fails in so many ways that I don't even know where to begin. In principle it is simple, specify the window, and move it. But specifying windows is not easy, two browsers are both named the same "Google Chrome". One can use their unique window IDs, but getting this information is not trivial (AFAIK, this is not returned upon execution). Then there is an :ACTIVE: option which is the most recently launched program, but there is no guarantee that the window is launched when control is returned to the command line. To make matters worse, one must specify global coordinates, as opposed to optional coordinates within a workspace/monitor.

Here is the approach I am currently taking. I have uploaded some scripts to GitHub (see here or here) which use wmctrl to move windows around.

share|improve this question
up vote 2 down vote accepted

You can determine which display to launch a program by using the following:

$ DISPLAY=":0.1" program_name

Some programs allow you to set their default display in a config file. mplayer is one of these programs. Append the following to ~/.mplayer/config


Your first display is 0.0. Your second display is 0.1. Your third display is 0.2.

share|improve this answer
is DISPLAY a command? It looks more like an argument (or variable) – puk Oct 19 '11 at 1:58
You are setting the display variable, yes. Regardless, adding DISPLAY=":X.X" before a program line should get you the desired results. – earthmeLon Oct 19 '11 at 17:07
Some programs, however, don't work well with the display variable when multiple sessions of the program are running. For example, you can put chromium-browser on either display, but it can only run on one display at a time. – earthmeLon Oct 19 '11 at 17:08

You can set which workspace a program launches to by GUI by installing CompizConfig Settings Manager from the Software Center.

First, open an instance of the program you wish to place.

Run CCSM and go to "Window Management", and active "Place Windows", click it and choose the "Fixed Window Placement".

Under "Windows with fixed viewport", click New. In the dialog that appears, click the "+" button. Then in the next dialog, click the "Grab" button, and then click the launched program and the "Add". Then set the values for the viewports: X=1, Y=1 is top left, X=1, Y=2 is bottom left, X=2, Y=1 is top right, X=2, Y=2 is bottom right.

If you do nothing else, this will set it for window class, but there are other options, such as ID, Type and more, but ID is the only one you cannot grab.

share|improve this answer
Yes that is like wmctrl and others in that it works best at moving either already open windows (in which case it's easier to just drag') or all types of similar windows (ie. all browsers in workspace 1 monitor 1, all terminals in W1 M2 , all gedits in W1M3...) However it fails pretty miserably at opening AND moving windows on a per window basis. – puk Oct 19 '11 at 18:22
contd: This could easily be fixed if I could manually assign a unique identifier (like the window ID or window title) but shell doesn't communicate too well with the window manager. I am currently writing a series of scripts to handle this, but they are not working. – puk Oct 19 '11 at 18:25

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.