在 Gnome 中的不同工作区中打开应用程序

发布于 2024-09-12 06:14:05 字数 515 浏览 8 评论 0原文

鉴于我的懒惰,我尝试编写一个 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 被正确分配;其余的在我执行脚本的工作区中打开从。

Given my laziness, I tried to write a bash script that opens at once some daily apps in different desktops. This script should work in Gnome. I've written that so far:

#!/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

... but it doesn't work. My apps open, but they won't be assigned to the desktops I specify :(.

I changed the value of sleep to 15., but only firefox & netbeans are assigned correctly; the rest opens in the workspace where I execute the script from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

横笛休吹塞上声 2024-09-19 06:14:06

感谢 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 

Thanks to Akira comment, I finally succeeded at making it work (the script runs at startup like a charm) Here is the new code:

#!/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 
浅忆流年 2024-09-19 06:14:06

签出 DevilsPie,它会监视窗口的创建并采取相应的操作。

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

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

checkout DevilsPie, it watches creation of windows and act accordingly.

Devil's Pie can be configured to detect windows as they are created, and match the window to a set of rules. If the window matches the rules, it can perform a series of actions on that window. For example, I can make all windows created by X-Chat appear on all workspaces, and the main Gkrellm1 window does not appear in the pager or task list.

Or you can use a window manager which is able to do the same in-house, eg. fluxbox.

稚气少女 2024-09-19 06:14:06

在 dconf 编辑器中:

org->gnome->shell->extensions->auto-move-windows
here is what it should look like:
['firefox.desktop:1','pidgin.desktop:2']

In dconf-editor:

org->gnome->shell->extensions->auto-move-windows
here is what it should look like:
['firefox.desktop:1','pidgin.desktop:2']
子栖 2024-09-19 06:14:06

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

我将此脚本称为 start-on-workspace

用法:start-on-workspace <工作区> <命令> [参数...

#!/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

This script will check if it's required to change the workspace, switches to it, starts the app, waits until the window is created and switches back to the origin namespace.
Because it uses wmctrl -l to check if a new window was created, it can handle fast as well as slow started applications, without the need to wait for for a static amount of seconds.

I called this script start-on-workspace.

Usage: 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文