Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Suppose I call shell-command from emacs for example (shell-command "evince"). Is it possible to move the application (in the present example evince) started this way automatically to desktop 5 in xmonad.

share|improve this question

3 Answers 3

In the spirit of do one thing and do it well, Devil's Pie was created for these kinds of issues with any standards-compliant WM (such as properly-configured XMonad, also see the FAQ).

Some configuration along the lines (adopted from this tutorial, I do not know if this way of matching Evince actually works, maybe some other way (see the docs) is needed) of

(if
  (is (application_name) "Evince")
    (begin
    (set_workspace 5)
    (maximize)
  )
)

should do the job. Note that Devil's Pie has been mentioned quite often around here, there might be more useful information just a click away.

share|improve this answer

A pure xmonad configuration is possible for that. In your .xmonad/xmonad.hs you need to setup a manageHook for that. I included more than one "rule" on purpose.

theManageHook = composeAll [
    -- send applications to the right workspace
    className =? "Evince" --> doShift "5",
    className =? "Pidgin" --> doShift "4"
    --- more settings ...
]

main = do
    xmonad $ gnomeConfig { 
        manageHook = theManageHook <+> manageHook gnomeConfig
    }

You can see the className of given Window with xprop and clicking on the desired window. className refers to the second entry in the xprop-output. If you only want some xproperties, xprop accepts them as arguments:

~ $ xprop WM_CLASS WM_NAME
WM_CLASS(STRING) = "evince", "Evince"
WM_NAME(STRING) = "Document Viewer"

More on that can be found in the Xmonad FAQ.

share|improve this answer
    
Thanks, I know that. I only want to move the application to a specific desktop if I start it from my emacs script. –  student Oct 19 '12 at 13:40
    
Hmm, maybe the initial WM_CLASS is different. Can you try to match the resource instead of the className? What do the emacs say about this? –  kronn Oct 19 '12 at 14:58

Here's an approach using xdotool to change the window's class then you can move it to Desktop 5 with XMonad or Devil's pie.

#!/bin/sh
$1 &
NEW_WINDOW_PID=$!

WINDOW_EXISTENCE=$(xdotool search --pid ${NEW_WINDOW_PID} 2> /dev/null) #is empty if the window hasn't finished opening.
COUNTER=0
while [[ -z $WINDOW_EXISTENCE && $COUNTER < 6 ]] #waits for the window to open
do
    WINDOW_EXISTENCE=$(xdotool search --pid ${NEW_WINDOW_PID} 2> /dev/null)
    sleep 1
    (( COUNTER++ ))
done

if [ $COUNTER != "6" ]; then
    NEW_WINDOW_ID=$(xdotool search --onlyvisible --pid ${NEW_WINDOW_PID}) #finds the window that was just opened
    xdotool set_window --class yay ${NEW_WINDOW_ID}; #change the class of the window to yay
fi

And then write a function in emacs

(defun window-in-desktop-5 (cmd)
  "start shell command on desktop 5"
  (interactive "sshell-command: ")
  (shell-command  (concat "/path/to/xdotoolscript " cmd)))

Whenever you call a program through the emacs function it will change the class name of the window as long as the PID of the window is the same as the function that called it otherwise the script will time out after six seconds.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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