Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Anyone know a library, preferably for ruby or python, that will let you access a list of open applications and let you manipulate them? All I really want to be able to do is change their geometry and minimize or close them. I've been messing around with ruby-gnome2 a bit but haven't found anything for manipulating windows other than the ones of your own process.

I'm using 10.10.

share|improve this question
Belongs to, because it's about programming. – Lekensteyn Jan 21 '11 at 8:51
It is on topic here because it is about programming on Ubuntu, even though Stack Overflow might be able to give better answers. – dv3500ea Jan 21 '11 at 9:44
i asked a similar question on SO and go almost no response. the response here has been amazing. askubuntu definitely has more knowledge on ubuntu programming than SO. – greg Jan 21 '11 at 16:48
up vote 4 down vote accepted

The easiest way to do this would be to shell out to wmctrl install wmctrl. You should read man wmctrl to see how to use it.

You could basically bind the command line to a 'Window' class and add methods to it that use wmctrl commands in the background.

class Window
    @@windows = []
    def self.get_windows
        `wmctrl -l`.split("\n").map do |str|
            @@windows <<' ')*)
    def initialize window_id, desktop_id, client_machine, window_title
        #set up object here
    #add other methods here

That should be a good starting point. It's not tested or anything but you should be able to work it out from here. You could now add instance methods, eg. change_geometry, which could utilise the -r <WIN> -e <MVARG> option.

You should familiarise your self with pipes and IO in general before doing this.

Perhaps when you have accomplished what you need to, you can distribute this as a ruby library and package it for Debian/Ubuntu.

share|improve this answer

You can use the Extended Window Manager Hints spec to tell the WM to change some windows. This is the trick that wmctrl uses.

Usually you need to use XLib to use EWMH, but for python there is this nice project: PyTile. It's a python program to tile the windows. Not only is it a nice example, it has wrapped the most important functionality into one class. Just download the source and take a look at, it does most of what you ask.

This example maximizes all the windows:

import Probe

for win in winlist:
share|improve this answer

Hey there, have a look at wmctrl. It's not an actual library, but a command line script that allows window manipulation via command line switches. You'd certainly be able to call it via system.

sudo apt-get install wmctrl

I use it in many shell scripts, and sometimes perl scripts using system()


share|improve this answer

Your Answer


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.