简体   繁体   English

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

[英]Open applications in different workspaces in Gnome

Given my laziness, I tried to write a bash script that opens at once some daily apps in different desktops.鉴于我的懒惰,我尝试编写一个 bash 脚本,该脚本可以立即打开不同桌面上的一些日常应用程序。 This script should work in Gnome.这个脚本应该在 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;我将 sleep 的值更改为 15.,但只有 firefox 和 netbeans 被正确分配; the rest opens in the workspace where I execute the script from.其余部分在我从中执行脚本的工作区中打开。

Thanks to Akira comment, I finally succeeded at making it work (the script runs at startup like a charm) Here is the new code:感谢 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 

In dconf-editor:在 dconf 编辑器中:

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

checkout DevilsPie , it watches creation of windows and act accordingly.结帐DevilsPie ,它会监视窗口的创建并采取相应的行动。

Devil's Pie can be configured to detect windows as they are created, and match the window to a set of rules. Devil's Pie 可以配置为在创建窗口时检测它们,并将窗口与一组规则匹配。 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. 例如,我可以让 X-Chat 创建的所有窗口出现在所有工作区中,而 Gkrellm1 主窗口不会出现在寻呼机或任务列表中。

Or you can use a window manager which is able to do the same in-house, eg.或者您可以使用能够在内部执行相同操作的窗口管理器,例如。 fluxbox .通量箱

Given I'm a lazy bastard, I tried to write a Bash script that opens at once some daily apps in different desktops.鉴于我是一个懒惰的混蛋,我尝试编写一个 Bash 脚本,该脚本可以立即打开不同桌面上的一些日常应用程序。 This script should work in Gnome.这个脚本应该在 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 :(.我的应用程序打开,但它们不会分配到我指定的桌面:(。

EDIT: I changed the value of sleep to 15... only firefox & netbeans are assigned correctly, the rest opens in the workspace where I execute the script from...编辑:我将 sleep 的值更改为 15 ......只有 firefox 和 netbeans 被正确分配,其余的在我执行脚本的工作区中打开......

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.因为它使用wmctrl -l来检查是否创建了新窗口,所以它可以处理快速启动和慢速启动的应用程序,而无需等待静态的几秒钟。

I called this script start-on-workspace .我将此脚本称为start-on-workspace

Usage: start-on-workspace <Workspace> <command> [argument...用法: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM