Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Activate particular X11 windows via a hotkey UNIX
One of the issues with using X11 under OS X is that the default window manager, quartz-wm, does not allow you to manipulate the properties of the various X windows very much. The biggest problem is that it is not possible to use a hotkey to bring to front and activate the exact X11 window that you want -- you have to resort to several mouse clicks on the Dock or on the Window menu. Most users are fine with having to use the mouse, but many people aren't -- we want to be able to assign a hotkey to everything. If you are happy using the mouse to switch X11 windows, read no further.

For the rest of you, here's a better description of the problem. Imagine that you have dozens of X11 windows open, and are working in the Finder. Now you want to use a hotkey to switch to a specific window, say emacs, while leaving all the other X11 windows alone. You'll quickly find that this is difficult to do.

The closest solution? Assign a hotkey to X11 using Peter Maurer's Butler, bringing up all the X11 windows at the same time, and forcing you to spend time wading through the mess so you can locate the one emacs window you really want. Even within X11, you first have to lookup which hotkey emacs is assigned to under the Window menu. What's worse, the hotkey assigned to a particular window under that menu changes as you open and close windows, so that it's impossible to keep a specific hotkey consistently assigned to a program. The Applications menu is useless for this purpose, because it always runs a new version of the program, instead of raising a previously active window. A drastic solution would be to switch window managers (to fvwm or something else), but then you would lose the pretty and fast quartz-wm graphics.

To the rescue comes a little program called xwit, plus Butler. The rest of this hint assumes that you aren't afraid of xterms and that you know how to assign hotkeys using Butler. Read on for the solution...

First, open the Terminal. You have to download, compile, and install xwit from the source, and you can do so through the following commands:

$ wget http://ftp.debian.org/debian/pool/main/x/xwit/xwit_3.4.orig.tar.gz
$ tar xvzf xwit_3.4.orig.tar.gz
$ cd xwit-3.4.orig
$ xmkmf
$ make
$ sudo mv xwit /usr/local/bin
You will have to type your passwrod. Users of tcsh (you know who you are) will also have to add rehash after they are done with the above. Now launch X11, and as an example, pop up an xeyes window:
xeyes &
Now minimize the xeyes window to the Dock by clicking on the yellow "minus" button on the title bar. Then, in an xterm type this:
/usr/local/bin/xwit -current -names xeyes
You will see that it will come back up to the front. If you had other X11 windows minimized, they would not come up -- only the xeyes window would have come up. This works with hidden and buried windows as well. For advanced usage, type xwit --help. Below we will use the window ID rather than -names, so that we know we are raising the right application, regardless of the window title.

Now we need to assign a hotkey to xwit. In Butler, create an AppleScript Smart Item. In the AppleScript source code, type the following:
do shell script "id=`/usr/X11R6/bin/xwininfo -root -children  
-tree | grep xeyes | /usr/bin/awk '{ print $1; exit; }'`;  
/usr/bin/open -a X11; /usr/local/bin/xwit -current -id  $id; 
/usr/local/bin/xwit -warp 1 1 -id $id"
Type in the above without any line breaks (put spaces where you see line breaks). Now assign a hotkey to that item. Now, no matter where you are on your Mac, you can press that hot key, and xeyes will come up to the front and be activated, without disturbing your other X11 windows. To activate a different X11 application, just change xeyes above to the application's name.

A technical note: I was not able to get the run shell script option working in latest version of Butler to run under Panther. Hence I resorted to the AppleScript solution. Also, Peter's Maurer's Witch does not seem to recognize individual X11 windows, so that's out as a possible solution.
    •    
  • Currently 3.00 / 5
  You rated: 5 / 5 (5 votes cast)
 
[10,964 views]  

Activate particular X11 windows via a hotkey | 12 comments | Create New Account
Click here to return to the 'Activate particular X11 windows via a hotkey' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Activate particular X11 windows via a hotkey
Authored by: wgscott on Oct 26, '05 07:06:53AM

Nice find!

During install, do this to have the man page:

sudo cp xwit.man /usr/local/share/man/man1/xwit.1

I haven't yet tried Butler, but two other possibilities (among many, no doubt):

1. Assign key bindings within the shell

2. Make contextual menu items with OnMyCommand

I think you have just made a lot of people very happy. This should be in fink. I'll make a package unless someone else wants to.



[ Reply to This | # ]
Activate particular X11 windows via a hotkey
Authored by: szabesz on Oct 26, '05 08:17:20AM

Peter Maurer has written Witch too. Have you tried it as well?



[ Reply to This | # ]
Activate particular X11 windows via a hotkey
Authored by: wgscott on Oct 26, '05 08:59:41AM

Read the last sentence.



[ Reply to This | # ]
Activate particular X11 windows via a hotkey
Authored by: szabesz on Oct 27, '05 12:44:58AM

Oh, thanx. I have skipped that I suppose :)



[ Reply to This | # ]
Mine wanted it in /usr/local/man
Authored by: Pausanias on Oct 26, '05 11:47:41AM

Thanks for the info about the man page. It wouldn't work in share though; I had to put it in /usr/local/man.



[ Reply to This | # ]
Correction to the article by the author
Authored by: Pausanias on Oct 26, '05 10:54:54AM
I sent in a correction that did not make it in. The snippet that says

{ print $1 }
should actually read

{ print $1; exit; }
Due to the fact that if there are multiple instances of the app open, the script won't work.

[ Reply to This | # ]
Correction to the article by the author
Authored by: robg on Oct 27, '05 11:48:50AM

I just fixed this; sorry about missing the email!

-rob.



[ Reply to This | # ]
does this work with xorg too?
Authored by: ubiquitin on Oct 26, '05 10:59:28AM
I've been using xorg instead of xfree86, see: xorg.darwinports.com

Any idea whether this will work with xorg too?

[ Reply to This | # ]
does this work with xorg too?
Authored by: Pausanias on Oct 26, '05 11:39:37AM

Yes it does. The beauty is that xwit works with any X11 installation or window manager.



[ Reply to This | # ]
Activate particular X11 windows via a hotkey
Authored by: wgscott on Oct 26, '05 01:33:14PM

Anybody know what the patch does (apart from preventing it from compiling)?



[ Reply to This | # ]
Activate particular X11 windows via a hotkey
Authored by: wgscott on Oct 27, '05 12:40:44AM

If you use zsh, define an alias

alias popx="xwit -pop -id"

Then type popx and hit the tab key to permute through all available windows.



[ Reply to This | # ]
Activate particular X11 windows via a hotkey
Authored by: Pausanias on Nov 30, '05 11:30:52AM

Another caveat: if you started Butler before X11, this won't work. For it to work, start Butler after running X11. If I have time I will post a modified version of the above script that works regardless of the Butler start order.



[ Reply to This | # ]