how to shift applications from workspace 1 to 2 using command
Solution 1:
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.
Solution 2:
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.
Solution 3:
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.