fbiville
fbiville

Reputation: 8960

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

Upvotes: 18

Views: 13052

Answers (4)

maximilize
maximilize

Reputation: 21

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

Upvotes: 2

fbiville
fbiville

Reputation: 8960

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 

Upvotes: 10

edward
edward

Reputation: 21

In dconf-editor:

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

Upvotes: 2

akira
akira

Reputation: 6147

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.

Upvotes: 2

Related Questions