Is there a command to go a specific workspace?

I'm trying to make a quicklist on the Workspace Switcher launcher that allows for quick switching to a certain workspace. (My friend sometimes uses my computer and just doesn't enjoy keyboard shortcuts, so I want to help him out.)

So is there a command one could type in a terminal that would force a certain workspace to be focused on?


You can use wmctrl.

Basics commands:
wmctrl -d to show all of your workspaces.
wmctrl -s <workspace_name> to change to a specific workspace.

If you are using Compiz, you will have to do a trick because Compiz "workspaces" are actually Viewports of a single Workspace.

Trick Instructions

Check the output of wmctrl -d For example, mine is:

0  * DG: 4098x2304  VP: 1366,0  WA: 0,23 1366x745  N/A  

This means that actually I have one Workspace of 4098 x 2304 instead of what I "think" I have (nine "workspaces", 3 x 3).
I was at what was supposed to be "workspace" 2, but actually I was at viewport (VP) 1366,0 (4098 / 3 = 1366) as showed by the output above.

So this is how it works: we take the whole Workspace and divide for the numbers of "workspaces" we "think" we have. In my case: 4098 / 3 = 1366 and 2304 / 3 = 768.

If I want to go to my "workspace" 1, the command is:

wmctrl -o 0,0

Then, if I want to go to my "workspace" 4, the command is:

wmctrl -o 0,768

If I want to go to my "workspace" 8, the command is:

wmctrl -o 1366,1536

If I want to go to my "workspace" 9, the command is:

wmctrl -o 2732,1536

Got it? ;-)

The -o flag "truncates" their values. In other words it changes the "workspace" where the actual pixel is belonging to. The following are equivalent:

wmctrl -o 0,0
wmctrl -o 1365,767

It is beautifully simple to achieve what you want with xdotool, which has multiple options for managing different workspaces (also known as 'desktops' within the program documentation). I find it can be very interesting and creative to string together commands from man xdotool; the commands I have formulated below might be useful in scripts.

Note: With some window managers, or if you are using compiz, you may need to use xdotool commands such as set_desktop_viewport and get_desktop_viewport. You may have to specify the commands in a different way like desgua suggests above, but for me the set_desktop and set_desktop_for_window commands proved most useful on a non-compiz system.)

(The solution is most useful for Xubuntu/Lubuntu users, or those who are not running compiz,etc.)

To list the number of current workspaces, enter

xdotool get_num_desktops

The following commands will only work if you have at least 1 other workspace.

To change focus to your workspace 1, just enter

xdotool set_desktop 1 

Then to return to the default workspace, enter

xdotool set_desktop 0

The workspace just needs to be specified as the last value in the command (1 or 2 or 3, etc).

To find the number of the workspace you are currently on, you could use

xdotool get_desktop

These commands could be used in scripts and they should be very useful for achieving what you what.

For how to switch applications to a particular desktop, see my answer here:

  • how to shift applications from workspace 1 to 2 using command

For more useful options available for workspace switching, consult man xdotool.


I have implemented a script that does what you want. Here it is: https://github.com/norswap/wmov/blob/master/wmov.sh

It works indeed as described in desgua's post. It also the capabilities to send windows to other workspaces.