Function to bring to focus, or remove focus, from an app.


I am trying to write a function to bring focus to an application foo on some desk ‘A’, while being in another desk.

Here is my code:

[code]DestroyFunc FuncFocusFoo
AddToFunc FuncFocusFoo
+ I ToggleFoo “Foo

+ I None ($$0, CirculateHit) Function MakeVisible
+ I TestRc (Match) Break
+ I Next ($$0, Circulate) Function MakeInvisible

AddToFunc MakeVisible
+ I MoveToDesk
+ I MoveToPage
+ I MoveToScreen
+ I Raise
+ I Iconify off
+ I WindowShade off

AddToFunc MakeInvisible
+ I Iconify On
+ I WindowId root 1 WarpToWindow 50 50[/code]

Any comments would be appreciated.


This is where the use of pages, rather than desks is more useful, since everything you have below can be simplified to something like this:

DestroyFunc FocusAndFlip
AddToFunc FocusAndFlip
+ I All ($0, CurrentDesk, !Iconic) FlipFocus

Which you can then use to call:

FocusAndFlip mozilla

For instance. But as you can see, if they’re on different desks, then that takes more work.

Careful here. Whenever you have to use wildcards to specify a likely window name, consider matching on “class”, so that you avoid any ambiguities in other windows being matched unexpectedly. If you search these forums, you will see I have mentioned this many times.

– Thomas Adam