Super User is a question and answer site for computer enthusiasts and power users. 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

How do tell an application to open in a specific workspace?

More info:

I like to have my C++ IDE in workspace 2, my Java IDE in workspace 3, and my email, browser and miscellaneous in workspace four. I also use a shell script that executes upon log in:

gnome-terminal & # WS 1
netbeans-6-9-1 & # WS2
qtcreator-2-0-1 & # WS 3
firefox & # WS 4
thunderbird & # WS 4

Of course currently it all opens in the current workspace... Is there a way for me to specify which workspace each command should start in?

Thanks in advance!

share|improve this question
If you always have these programs running, the easiest and simplest way is to load them all up where you want them and 'remember applications when logging out' – MrStatic Jan 12 '11 at 1:23
@MrStatic : Thanks for the suggestion, but I do need it to be in a shell script for other reasons - and for that I cannot 'remember applications when logging out' – bguiz Jan 12 '11 at 2:38
up vote 5 down vote accepted

You could use devilspie to set rules for which windows go on which workspace.

See the docs for an example of exactly that.

But MrStatic has a good suggestion too. Try that one first, you might not even need your shell script.

If you need it to be a command you can use in a shell script, have a look at wmctrl.

share|improve this answer
thanks for the suggestion, will check it out - I would still consider a CLI-only solution to be a superior solution though, so if you have any ideas for one, let me know! – bguiz Jan 12 '11 at 2:41
Try wmctrl. I added a link in my answer above. – Mikel Jan 12 '11 at 3:22

I have tried the wmctrl tool and found that the easiest solution that worked for me is to move window with the following command:

wmctrl -r <WindowName> -t <WorkspaceNumber>

Note that the workspace numbers starts from 0. Last you can move to your preferred workspace with the command:

wmctrl -s <WorkspaceNumber>
share|improve this answer

I am fairly certain it is impossible to do. The reason seams to be that windowing environments like GNOME expect software to handle this, and software makers expect windowing environments to handle this.

Devilspie is a good idea, but it does pattern matching (ie. if name == 'google-chrome'). So what happens if I open two browsers? They both get moved to the same workspace? I have 6x3=18 workspaces, each one with a particular instance of chrome. It would help if I could rename these programs (ie 'google-chrome1', 'google-chrome2'...) but I can't find a way to do that. So we have to use wmctrl.

wmctrl is a little better b/c in addition to using window titles, you can also use window IDs or just use the currently highlighted window. Window IDs are a pain to get b/c they are not immediately generated. See below

gedit 1.txt
#get window ID by looking at wmctrl -l store in windowID
wmctrl -i -r $windowID -e 0,3660,0,-1,-1

but then control is not returned to the command line until AFTER gedit exits. All we have to do to get around this is put a & sign

gedit 1.txt &
#get window ID by looking at wmctrl -l store in windowID
wmctrl -i -r $windowID -e 0,3660,0,-1,-1

but now control is, 99.999% of the time, returned to the command line BEFORE the window managers launches the window and there is no way to find the window id. One has to set up a very complex looping technique to test to see if any new windows have been created, and to guess whether it is the window we are looking for.

Checking for the active window via the flag :ACTIVE: has the same problem, it does not wait for the program to finish running.

wmctrl strikes me as a very weird program. It seems like it was designed for people without a mouse, or unable to physically drag their programs across workspaces.

share|improve this answer
The OP said the browser goes on workspace four. If it needed to be possible to open browsers on other workspaces after the session startup script runs, the last command in that script could be sleep; pkill devilspie. – Mikel Aug 20 '14 at 14:53

You must log in to answer this question.

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