Function to open windows on the page they were launched from

I often find myself starting an program like Pidgin or Thunderbird which takes a while to load. Because I have multiple pages on my desktop I like to open each program on a separate page and pan around my desktop. The problem I have had is that I will open the program on one page and then either have to wait for it to load and can’t do anything else, or move to another page, say to carry on reading a web page, and then have the program appear on top of the window I am looking at, and then have to move it out of the way, which is annoying.

My solution is a function to load the application on the same page that was being viewed when it was called:

# $0 is name of window, $1 is command string, $2 is an ID
AddToFunc SamePage
 + I SetEnv PageX$2 $[page.nx]
 + I SetEnv PageY$2 $[page.ny]
 + I Exec exec $1
 + I None ("$0") Wait "$0"
 + I Next ("$0") MoveToPage $[PageX$2] $[PageY$2]
 + I SetEnv PageX
 + I SetEnv PageY

Now my root menu is along these lines:

AddToMenu RootMenu      
+               "Thunderbird"   SamePage "*Thunderbird" thunderbird 1
+               "Firefox"       SamePage "*Firefox" firefox 2
+               "Pidgin"        SamePage "Buddy List" pidgin 3

If the window doesn’t load then you’ll need to press Ctrl-Alt-Esc to get out of the Wait.

So setting a Style line with SkipMapping doesn’t work for you, because…?

Style $[w.class] StartsOnPage $[desk.n] $[page.nx] $[page.ny]

Based on some precondition you specify.

+ I Wait $0
+ I Next ($0) .....

But this is silly to begin with – no quotes needed. My snippet here is what you should be using,

– Thomas Adam

The function below does it with the styles as you suggested.

AddToFunc SamePage2
+ I Style "$0" SkipMapping, StartsOnPage $[desk.n] $[page.nx] $[page.ny]
+ I Exec exec $1

Quotes round $0 are necessary because there may be a space in it, such as “Buddy List” with pidgin.

Again, missing my point – for a window’s name, yes. But with Wait and Next where ther expanded variable is already quoted, no need for quotes.

Oh, and you’re welcome, I suppose.

– Thomas Adam