12

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:

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

bguiz
  • 2,141

5 Answers5

10

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>
slm
  • 10,859
VGe0rge
  • 208
4

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.

Mikel
  • 9,184
1

I use this basic structure in scripts to open a specific set of applications in specific workspaces..the example opens my terminal and moves it to workspace 1...

cd
gnome-terminal
until wmctrl -l | grep -q "me@mypc ~"; 
do
    sleep 0.1
done
wmctrl -r "me@mypc ~" -t 1
1

Install wmctrl

sudo apt install wmctrl

And create a script (in this example thunderbird on the second workspace (-t 1)):

#!/bin/sh
(thunderbird &)  & sleep 5 && 
sh -c "wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"

To know your application name on wmctrl you can view it by taping on your terminal :

wmctrl -l

And replace it with the correct name in the script.

Be carrefull with the capital letter ("Thunderbird" not "thunderbird") !!

Other example with firefox on the 3d workspace (-t 2):

#!/bin/sh
(firefox &)  & sleep 5 && 
sh -c "wmctrl -i -r `wmctrl -l | grep Firefox` -t 2"

Work on Debain 10 with Cinnamon. But should work for all

pzim
  • 11
-1

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.

puk
  • 717