When I start GUI program, it's window appears on the currently active desktop (essentially, on a random desktop).

How to make it appear on a specific desktop? For example, at startup I want certain programs to be started and distributed to desktops.

I've already set up config file of openbox to force some programs to always start on specific desktop.

Ideally it should be like:

start_on_desktop 1 gnome-terminal --tab -e program1 --tab -e program2
start_on_desktop 2 gnome-terminal --tab -e program3 --tab -e program4
start_on_desktop 3 firefox

It should be able to start the same program on other desktop.

Also dislike when I start program while being on desktop X then switch to desktop Y and SUDDENLY a program which should be on X appears on Y. When I start lots of programs on and switch often between desktops they end up being in chaos and I need to collect them together and redistribute sanely.

Also I want the first initial gnome-terminal to be on desktop 3, but I also want subsequent gnome-terminals to be on the desktop where I pressed the keystroke (also configured in openbox) that launches gnome-terminal.


try devilspie:

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.
  • I want start two the same applications with the same windows (e.g. two gnome-terminals) on different desktops. openbox itself can place windows matched by window and class name to a desktop. – Vi. Jan 22 '11 at 23:43
  • First thought: modify the script to list windows before and after starting the command, then diff them, and if there's only one line different, grab the window id for that line. Or: modify the script to try matching the window name with the first word of the command line passed to start_on_desktop. – Mikel Jan 23 '11 at 6:13
  • @Mikel: has your comment something to do with my answer? – akira Jan 25 '11 at 14:48
  • @Vi. With gnome-terminal, at least, one can give devilspie something to grab onto with the gnome-terminal option --window-with-role. – Darael Mar 3 '13 at 15:46

Here's a first pass at a script to do it using wmctrl.

Works for me with Metacity, and should work in Openbox because it's also EWMH compliant.

Relies on GNU sleep. If you don't have that, change tries to 10 and sleeptime to 1.



if test $# -lt 2
    echo "Usage: start_on_desktop <desktop> <command> [<command args>...]" 1>&2
    exit 2

while test $tries -gt 0
    sleep $sleeptime
    windows=$(wmctrl -l -p)
    while read _id _desktop _pid _rest
        _ppid=$(ps -o ppid= -p $_pid)
        if test "$_pid" = "$pid" -o "$_ppid" = "$pid"
            break 2
    done <<EOF
    tries=$((tries - 1))
if test -n "$id"
    wmctrl -i -r "$id" -t "$desktop"
    exit $?
    echo "Window not found" 1>&2
    exit 1

And here's a script to find out the current desktop.



desktops=$(wmctrl -d)
while read id stat rest
    if test "$stat" = "*"
        echo $id
        exit 0
done <<EOF
echo "Cannot determine current desktop" 1>&2
exit 1

You could use it like this to move any application that takes a long time to start back to the desktop where you started it:

start_on_desktop $(current_desktop) <firefox or eclipse or whatever>

I guess you would put your four start_on_desktop lines in .Xclients or .xsession.

  • wmctrl -l -p is often like 0x03000012 2 0 N/A 0.5.2 svn for programs I want to run using that script. – Vi. Jan 23 '11 at 3:51
  • And, for example, GVim reports just invalid PID. – Vi. Jan 23 '11 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.