how to shift applications from workspace 1 to 2 using command
Is there any way I can switch the application running in one workspace to another on command line? I use Ubuntu 10.04
UPDATE1
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 Chromenow 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?
UPDATE2
I tried
wmctrl -r 0x05000072 -t 2
but the windows had no effect and they remained in same work space.
17 Answers
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 1If 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 1Alternatively 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.
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 1Or 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 %@ 1This 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.
Here is a script of mine that implements what you ask:
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.
1If you are using compiz, then look here at the compiz wiki. There you find several examples. Look at the "put" plugin.
Example
./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 5 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):
#!/bin/bash
SCREEN_W=$(xwininfo -root | sed -n 's/^ Width: \(.*\)$/\1/p')
SCREEN_H=$(xwininfo -root | sed -n 's/^ Height: \(.*\)$/\1/p')
NAME="$1"
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 0If 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.
Try:
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 or
wmctrl -r "moz" -t `wmctrl -d | grep "code" | cut -d" " -f1`but
wmctrl -r -i 0x03a0008e -t `wmctrl -d | grep "code" | cut -d" " -f1`Just work me once, and I don't know why!