14

考虑到我的懒惰,我尝试编写一个 bash 脚本,在不同的桌面上同时打开一些日常应用程序。这个脚本应该在 Gnome 中工作。到目前为止,我已经写过:

#!/bin/bash
firefox &
thunderbird &
/usr/bin/netbeans --locale en &
amsn &
gnome-terminal &
sleep 2
wmctrl -r firefox -t 0 && wmctrl -r netbeans -t 1 && wmctrl -r gnome-terminal -t 2 && wmctrl -r amsn -t 6 && wmctrl -r thunderbird -t 7

...但它不起作用。我的应用程序打开了,但它们不会分配给我指定的桌面:(。

我将 sleep 的值更改为 15。,但只有 firefox 和 netbeans 被正确分配;其余部分在我执行脚本的工作区中打开。

4

4 回答 4

7

感谢 Akira 的评论,我终于成功地让它工作了(脚本在启动时像一个魅力一样运行)这是新代码:

#!/bin/bash
wmctrl -n 8

firefox &
thunderbird &
/usr/bin/netbeans --locale en &
amsn &
gnome-terminal &
sleep 15

wmctrl -r firefox -t 0
wmctrl -r netbeans -t 1 
wmctrl -r terminal -t 2 
wmctrl -r amsn -t 6 
wmctrl -r thunderbird -t 7

#focus on terminal
wmctrl -a terminal 
于 2015-08-31T16:02:31.463 回答
2

结帐DevilsPie,它会监视窗口的创建并采取相应的行动。

Devil's Pie 可以配置为在创建窗口时检测它们,并将窗口与一组规则匹配。如果窗口符合规则,它可以对该窗口执行一系列操作。例如,我可以让 X-Chat 创建的所有窗口出现在所有工作区中,而 Gkrellm1 主窗口不会出现在寻呼机或任务列表中。

或者您可以使用能够在内部执行相同操作的窗口管理器,例如。通量盒

于 2010-07-28T08:48:36.373 回答
2

在 dconf 编辑器中:

org->gnome->shell->extensions->auto-move-windows
here is what it should look like:
['firefox.desktop:1','pidgin.desktop:2']
于 2013-07-09T13:22:54.510 回答
0

此脚本将检查是否需要更改工作区、切换到工作区、启动应用程序、等到创建窗口并切换回原始命名空间。因为它用于wmctrl -l检查是否创建了新窗口,所以它可以处理快速和慢速启动的应用程序,而无需等待静态的秒数。

我调用了这个脚本start-on-workspace

用法:start-on-workspace <Workspace> <command> [argument...

#!/bin/sh -e
# get the target ns
target=$(($1 - 1))
shift

# get the current ns
current=$(wmctrl -d | grep '*' | cut -d' ' -f1)
if [ $current != target ]; then
    # switch to target ns
    wmctrl -s $target
fi

# get a checksum of currently running windows
a=$(wmctrl -l | cut -d' ' -f1 | sha1sum | cut -d' ' -f1)
b=$a

# start the app
$@ &

# wait until there is a change on the window list
while [ $a = "$b" ]; do
    a=$(wmctrl -l | cut -d' ' -f1 | sha1sum | cut -d' ' -f1)
    sleep 0.1
done

# switch back to the origin namespace if needed
if [ $current != target ]; then
    wmctrl -s $current
fi
于 2021-06-09T11:27:32.003 回答