如何使用命令将应用程序从工作区1转移到2

有什么办法可以在命令行上将在一个工作区中运行的应用程序切换到另一个工作区吗? 我使用Ubuntu 10.04

UPDATE1
根据以下建议

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 

现在我打字的时候

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

那么如何正确使用它上面的错误是什么?

UPDATE2
我试过了

wmctrl -r 0x05000072 -t 2

但窗户没有效果,他们仍然在同一个工作空间。

如果您使用像Metacity(Unity 2-d)这样的兼容窗口管理器,则可以使用wmctrl将窗口切换到另一个桌面。 语法是wmctrl -r :ACTIVE: -t 。 您还可以使用wmctrl -s 更改当前桌面。 桌面编号从0开始。在一行中,这将是:

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

如果要将活动窗口以外的窗口切换到另一个桌面,请使用标题中的文本作为-r的参数。 例如:

 wmctrl -r "Chromium" -t 1 

或者,您可以使用wmctrl -l列出可用的窗口并将id号传递给-r而不是特殊字符串:ACTIVE: . 传递id时,还需要添加-i。 例如:

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

(wmctrl可以使用sudo apt-get install wmctrl安装在Ubuntu上。)目前,这似乎不适用于标准Unity,不幸的是。

这是我的一个脚本,它实现了你的要求: https : //github.com/norswap/wmov/blob/master/wmov.sh

在它的当前forms中,它可以通过选择显式桌面编号或指示桌面方向,将窗口(通过匹配不区分大小写的字符串与子字符串标题(例如wmctrl -r选项)选择)发送到其他桌面从当前的桌面。

例如:

 ./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) 

它确实如desgua的post所述。 它还具有将窗口发送到其他工作区的function。

如果您正在使用compiz,请查看compiz wiki 。 你在那里找到几个例子。 看看“put”插件。

 ./compiz-dbus-send.py put put_viewport_right_key 

首先,冒号是:ACTIVE: magic标记的一部分,用于指示活动窗口。 你通常不想要它。 其次,您需要引用带有空格的字符串。

您还可以获取窗口ID(每行0x... )并使用它而不是尝试使标题工作。

 $ wmctrl -r 'OMG! Ubuntu! | wmctrl - Chromium' -t 2 # wherever it is, move it to 2 $ wmctrl -r 0x0482a380 -t 2 # same thing 

可以使用xdotool执行此xdotool如果您使用compiz此解决方案可能不适用,因此请记住这一点。

要将特定窗口(活动窗口)切换到其他工作区,您可以使用

 xdotool getactivewindow set_desktop_for_window 1 

或者对于脚本,您可能希望将特定程序的窗口切换到给定的工作区:

 xdotool search --class firefox set_desktop_for_window %@ 1 

此命令搜索并找到firefox窗口并将它们传输到工作区1,在工作区1中它们将显示为最小化。 要将firefox返回到默认桌面,只需在命令末尾用0替换1即可。 要将另一个窗口发送到另一个工作区,只需将firefox替换为另一个程序名称即可。

使用%@来表示从--search参数传递的窗口是至关重要的,就好像你不会传输窗口一样。

有关更多信息,请参阅man xdotool和Ubuntu联机帮助页。

通过修改它作为此问题的解决方案给出的脚本,以下“将”给定窗口“带到”当前工作空间(在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 0 

如果需要任意工作空间,则需要添加/减去相应的$SCREEN_W / $SCREEN_H ,与窗口远离目标工作空间的工作空间一样多。

尝试:

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

让我解释一下:在wmctrl节目的帮助下

  -r  -t  Move the window to the specified desktop.  A desktop number. Desktops are counted from zero.  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可以列出所有工作区,在我的计算机中现在显示如下:

 0  -  DG:1600x900 VP:N / A WA:0,0 1600x868代码
 1 * DG:1600x900 VP:0,0 WA:0,0 1600x868播放 
 2  -  DG:1600x900 VP:N / A WA:0,01600x868研究

*表示当前工作空间

BTW, wmctrl -l是列出所有窗口(你已经知道),在我的电脑中它们现在是:

 0x05400008 1个用户-LinuxMint终端
 0x03a0008e 0 user-LinuxMint Mozilla Firefox

由于“DESK”必须是数字,我使用grep “workspace name” | cut -d" " -f1 grep “workspace name” | cut -d" " -f1得到它。

例如,如果我想将Firefox移动到工作区“代码”,我可以使用:

 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` 

只工作一次,我不知道为什么!