Is there any way I can switch the application running in one workspace to another on command line? I use Ubuntu 10.04

As per suggestions below

 wmctrl -l
0x02200003 -1 bond Bottom Expanded Edge Panel
0x02200049 -1 bond Top Expanded Edge Panel
0x02000020  0 bond x-nautilus-desktop
0x04e00004  0 bond bond@bond: ~
0x0482a380  0 bond OMG! Ubuntu! | wmctrl - Chromium
0x05000072  0 bond how to shift applications from workspace 1 to 2 using command - Ask Ubuntu - Stack Exchange - Google Chrome

now when I type

wmctrl -r :OMG! Ubuntu! | wmctrl - Chromium: -t 2 No window was specified.

So how to use it properly what is the mistake in above?

I tried

wmctrl -r 0x05000072 -t 2

but the windows had no effect and they remained in same work space.

  • I've updated my answer with better information about the use of -r and -i. The argument to -r should be enclosed in "quotation marks" if it contains spaces. If the argument to -r is the window id, you also need to specify -i on the command line. – user8979 Mar 21 '11 at 22:01

If you are using a compliant window manager like Metacity (Unity 2-d) you can use wmctrl to switch a window to another desktop. The syntax is wmctrl -r :ACTIVE: -t <DESKTOP>. You can also change your current desktop using wmctrl -s <DESKTOP>. Desktop numbers start at 0. On one line, this would be:

wmctrl -r :ACTIVE: -t 1; wmctrl -s 1

If you want to switch a window other than the active one to another desktop, use text from the title as the argument to -r. For example:

wmctrl -r "Chromium" -t 1

Alternatively you can use wmctrl -l to list the available windows and pass the id number to -r instead of the special string :ACTIVE:. When passing an id, you also need to add -i. For example:

$ wmctrl -l
0x03e00189  0 hostname Ask Ubuntu - Chromium
$ wmctrl -i -r 0x03e00189 -t 2

(wmctrl can be installed on Ubuntu with sudo apt-get install wmctrl.) At present, this doesn't seem to work with standard Unity, unfortunately.

  • @skyblue Great info.See one thing I am not clear is how do I know the desktop window no and also what I am looking for is suppose chrome is running and I want chrome to switch from my current desktop to another one then how to go for this. – Registered User Mar 21 '11 at 16:58
  • If you are using the Chrome browser (which has "Chromium" in the title, you should be able to use wmctrl -r "Chromium" -t 1 as skyblue mentions in his answer, as long as you are using a compliant window manager like Unity-2d. – John S Gruber May 24 '12 at 18:35

It is possible to do this with xdotool, but if you are using compiz this solution might not be applicable, so please keep this in mind.

To switch a particular window (the active window) to a different workspace, you could use

xdotool getactivewindow set_desktop_for_window 1

Or for a script you might want to switch a particular program's windows to a given workspace with:

xdotool search --class firefox set_desktop_for_window %@ 1

This command searches and finds the firefox window(s) and transfers them to workspace 1, where they will appear minimised. To return firefox to the default desktop, just replace the 1 with a 0 at the end of the command. To send a different window to another workspace, just replace firefox with another program name.

It is crucial you use %@ to represent the windows passed from the --search parameter, as if you don't no windows will be transferred.

For more information, see man xdotool and the Ubuntu manpages online.

  • You don't have to use %@. It moves every firefox window, %@ is for every found window. If you have one and you don't use it, it may not work because there are often several "invisible" windows. For that, you need to use --onlyvisible. Then, you can leave out the %@, so only the first window by launching order will be moved. The others can be selected, if you have several, via %N where N is a natural number. – Haggra Nov 4 '20 at 23:13

Here is a script of mine that implements what you ask: https://github.com/norswap/wmov/blob/master/wmov.sh

In it's current form, it can send windows (selected by matching a case-insensitive string against substrings title, like for the wmctrl -r option) to other desktops, either by choosing an explicit desktop number, or by indicating the direction of the desktop from the current desktop.

For instance:

./wmov.sh mov "Google Chrome" 3 # sends Chrome to desktop 3 (bottom left)
./mov.sh mov Skype right # sends Skype to the desktop to the right of
                         # the current desktop (if any)

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

  • I like this solution, because it can identify windows with partial matches of the window name, especially useful when programs modify part of their name, depending on context. Calling windows by name is easier than looking up their PIDs. The drawback is that if there are multiple windows with the same string in the name, one can't predict which one wmov.sh will grab. – Andrew P. Dec 2 '16 at 0:25

If you are using compiz, then look here at the compiz wiki. There you find several examples. Look at the "put" plugin.


./compiz-dbus-send.py put put_viewport_right_key

Firstly, the colon is part of the :ACTIVE: magic token to indicate the active window. You don't want it normally. Second, you need to quote strings with spaces in them.

You can also get the window ID (the 0x... at the start of each line) and use that instead of trying to make the title work.

$ wmctrl -r 'OMG! Ubuntu! | wmctrl - Chromium' -t 2 # wherever it is, move it to 2
$ wmctrl -r 0x0482a380 -t 2 # same thing
  • Another way to get window IDs is to run xwininfo and then click on the window whose ID you want. – geekosaur Mar 21 '11 at 17:56
  • I tried your method but it did not had any effect on the window in question. – Registered User Mar 21 '11 at 18:37
  • @Registered User: What window manager? (wmctrl -m) – geekosaur Mar 21 '11 at 18:50
  • sorry for the delayded Reply wmctrl -m Name: compiz Class: N/A PID: N/A Window manager's "showing the desktop" mode: OFF – Registered User Mar 23 '11 at 13:11
  • Hrm. I'm going to guess, based on the suggestions to use Compiz plugins, that Compiz doesn't actually implement the full EWMH spec so wmctrl isn't going to work. (Specifically, it has to listen for PropertyChange events on the root window for particular properties and then act on the contents of those properties.) – geekosaur Mar 23 '11 at 13:28

By modifying a bit the script that it's given as solution to this question, the following "brings" a given window to the current workspace (in compiz):


SCREEN_W=$(xwininfo -root | sed -n 's/^  Width: \(.*\)$/\1/p')
SCREEN_H=$(xwininfo -root | sed -n 's/^  Height: \(.*\)$/\1/p')


wmctrl -xlG | awk -v NAME="$NAME" '$7==NAME {print $1}' | while read WINS; do wmctrl -ir "$WINS" -e "0,0,0,$SCREEN_W,$SCREEN_H"; done

exit 0

If an arbitrary workspace is desired, then it's a matter of adding/substracting the corresponding $SCREEN_W/$SCREEN_H, as many times as workspaces a window is away from the target one.



wmctrl -r “window name(or any string in the title)” -t `wmctrl -d | grep “workspace name” | cut -d" " -f1`

let me explain: in the help of wmctrl shows

    -r <WIN> -t <DESK>   Move the window to the specified desktop.
    <DESK>               A desktop number. Desktops are counted from zero.
    <WIN>          This argument specifies the window. By default it's
                   interpreted as a string. The string is matched
                   against the window titles and the first matching
                   window is used. The matching isn't case sensitive
                   and the string may appear in any position
                   of the title.

                   The -i option may be used to interpret the argument
                   as a numerical window ID represented as a decimal
                   number. If it starts with "0x", then
                   it will be interpreted as a hexadecimal number.

wmctrl -d can list all the workspaces, in my computer now shows as following:

0  - DG: 1600x900  VP: N/A  WA: 0,0 1600x868  code
1  * DG: 1600x900  VP: 0,0  WA: 0,0 1600x868  play 
2  - DG: 1600x900  VP: N/A  WA: 0,01600x868  research

* means the current workspace

BTW, wmctrl -l is to list all the windows(which you already known), in my computer now they are:

0x05400008  1 user-LinuxMint Terminal
0x03a0008e  0 user-LinuxMint Mozilla Firefox

since the "DESK" must be the number, I use grep “workspace name” | cut -d" " -f1 to get it.

For example, if I wanna move Firefox to workspace"code" , I can use:

wmctrl -r "firefox" -t 0 


wmctrl -r "moz" -t `wmctrl -d | grep "code" | cut -d" " -f1`


wmctrl -r -i 0x03a0008e -t `wmctrl -d | grep "code" | cut -d" " -f1`

Just work me once, and I don't know why!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.