xdotool project page posted
Posted Mon, 25 Jun 2007
xdo updates: window operations and searching
Posted Fri, 22 Jun 2007
% ./xdotool search "Mozilla Firefox" 31457484 % xwininfo -id 31457484 | egrep 'Width|Height' | paste - - Width: 1278 Height: 1008 % ./xdotool windowsize `./xdotool search "Mozilla Firefox"` 500 500 % xwininfo -id 31457484 | egrep 'Width|Height' | paste - - Width: 500 Height: 500This new 'search' command will walk the list of windows in X and basically output any windows with a matching title, name, or class. In this case, I have 1 "browser" window open under firefox that has "Mozilla Firefox" in the title. So I then resize it to 500x500, trivially.
Longer summary of today is that I added 4 new functions to xdotool:
- windowsize <windowid> <width> <height>
- windowfocus <windowid>
- windowmove <windowid> <x> <y>
- search <regexp>
Turns out XTEST works as I'd expect, and this example will do what you think, and switch to the 2nd console (assuming you're running one).
% ./xdotool key "ctrl+alt+F2"
Goal: Focus the first window found that is a local xterm (ie; not ssh'd anywhere). My xterms have title with 'host(pwd) - activity' in them. So if my local host is 'snack' I can do:
# Look for xterms starting with 'snack(' and focus the first one ./xdotool search '^snack\(' | head -1 | xargs ./xdotool windowfocusAnd magically one of the xterms running a shell locally is focused. I can see this being pretty useful.
Today's code: navmacro-20070622.tar.gz.
xdo "beta" release
Posted Wed, 20 Jun 2007
The result so far is as follows:
- xdo is now a library, so you can simply call xdo_click(...) and it will handle all the hard stuff for you for the case that you want to use this in your own code.
- xdotool is the commandline interface to the xdo api.
- navmacro (bad name) is a very small gtk launcher. Basically it's an input box that runs the contents when you hit enter
So right now, I can do this:
- Select a piece of text in an xterm
- Activate navmacro and type 'ffsp' and hit enter
- Enjoy the fact that firefox has been told to search for the contents of my clipboard
Interested in the code? Download navmacro-20070620.tar.gz.
Note: navmacro works on my ubuntu and freebsd systems just fine. However, xdotool crashes at the end when I do free(xdo->charcodes) only on my Ubuntu system. Uncertain why, I'm way too tired to debug.
xdo - do (keyboard or mouse) things in X
Posted Mon, 18 Jun 2007
Yesterday, I talked about macros. I spent some time coding today and I now have a tool that will let you execute raw keyboard and mouse input into X using the XTEST extension.
The primary example I used was focusing firefox's URL bar without the mouse. The sequence was this: Switch to Desktop 2 (I press Alt+2), focus firefox's URL bar (using control+l) and clear it.
The result is a simple tool I'm tentatively calling 'xdo'. You can download the source here. Compile instructions are at the top of the file.
The top of xdo.c details the implemented commands, so let's cut to an example:
% echo 'key alt+2; sleep 1; key ctrl+l; key BackSpace' | ./xdoIt does exactly what you think. The 'sleep' command has values in milliseconds, and is only necessary to slow down so that events can propgate fast enough (window focus changes, etc).
Another reasonable example would be to say "firefox, open a new tab and load the URL in my clipboard":
# My clipboard contains a valid url, say, "http://www.google.com/" (echo "key alt+2; sleep 1; key ctrl+l; key BackSpace;" echo "move 55 55; sleep 1; click 2; key Return") | ./xdoSeems complex, but look at what's really happening: Go to desktop 2, focus urlbar, hit backspace (clearing it), move the mouse cursor to 55,55 (a point inside the urlbar for me), hit middle mouse button to paste.
Change "ctrl+l" to ctrl+k (unix firefox) to focus the "Search" box instead, and change the 'move' command to cursor over the search box to paste instead, and suddenly you can bind a simple keystroke to search for whatever is in your X clipboard. Useful.
One of the neater features is that you can 'type' text:
% echo 'type echo hello there; key Return' | ./xdo echo hello there % echo hello there hello there