Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to start an application within Ubuntu (xfce or gnome) and via the command line and was wondering if there's a generic way to set the dimensions of a given window of a given app that is currently running?

share|improve this question

4 Answers 4

Specific to XFCE there is pyxfce which will allow you to do that using python language. Pyxfce is an API that, among other things, lets you communicate with the window manager. To use this from the command line would require you to prepare a script first.

Depending on your use, the importance of using a X-based API using X window IDs (such as python-xlib or xdotools mentioned in another answer) versus others that use strings matching window titles (like wmctrl), is that there can be no confusion between windows, which may have the same keywords in their respective title.

share|improve this answer
#!/bin/bash
#get window pid under mouse
xprop -id $(xwit -current -print | cut -d ":" -f 1) | grep _NET_WM_PID | cut -d "=" -f2 | cut -c 2-
share|improve this answer

This is easier to do if you install something like xdotool. Then you can do:

xdotool search --name "window name" windowsize 300 400

replace "window name" with a name or reg ex appearing in the window title (you can also search by window class and a variety of other things), and the two numbers appearing after windowsize are the width and height, respectively. (You can also use percents, etc.) See man xdotool once it's installed.

If you're on Lucid or earlier, I recommend going to the xdotool website to get a newer version, however.

share|improve this answer

If the window manager supports Xlib there is. This uses Python to set the window's size to 500x300:

WIDTH, HEIGHT = 500, 300
import Xlib
import Xlib.display

display = Xlib.display.Display()
root = display.screen().root
windowID = root.get_full_property(display.intern_atom('_NET_ACTIVE_WINDOW'), Xlib.X.AnyPropertyType).value[0]
window = display.create_resource_object('window', windowID)
window.configure(width = WIDTH, height = HEIGHT)
display.sync()

The hard part is getting the window ID; in the above code it got the ID of the active window. If you want another ID, you can use something like this to get the title and controlling PID of each window, and choose the right ID based on those:

windowIDs = root.get_full_property(display.intern_atom('_NET_CLIENT_LIST'), Xlib.X.AnyPropertyType).value
for windowID in windowIDs:
    window = display.create_resource_object('window', windowID)
    name = window.get_wm_name() # Title
    pid = window.get_full_property(display.intern_atom('_NET_WM_PID'), Xlib.X.AnyPropertyType) # PID
share|improve this answer

Your Answer

 
discard

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.