Pages by Andreas B. M. Hofmeier
An-H
email Impressum/Note Privacy
http[s]://www.abmh.de/en/papers/linux/set-window-position-geometry-from-script.html

Like to be free? ... then: Fight for Freedom

set window size / geometry from a script

I am using my Laptop with dual-head. The challange is to move the windows on the external screen to the internal one if the laptop is used without the external monitor. xprop do not work in my case:
andreas@LBlacky:~ > xprop -set WM_SIZE_HINTS.Geometry  640x480+10+10
xprop: error: unsupported conversion for WM_SIZE_HINTS.Geometry
so I searched and found wmctrl which works perfect. I wrote the following little script:
#!/bin/bash

# This script sets the windows geometry off all windows which name conatins $1 to
# geometry $2. Notice the format of $2: x,y,w,h
#       x,y is the position of the top left corner of the window, and w,h  is  the
#       width  and  height of the window, with the exception that the value of
#       -1 in any position is interpreted to mean that  the  current  geometry
#       value should not be modified.

# GPL, (c) Andreas Hofmeier http://www.abmh.de/

wmctrl -l | grep -i $1 | while true; do
  read LINE
  if [ "$LINE" == "" ]; then
    break;
  fi
##  WMNAMW=${LINE:22}
##  wmctrl -r "$WMNAMW" -e 0,$2
  wmctrl -i -r $(echo $LINE | awk '{print $1}') -e 0,$2
done

#example:
# $0 kontact 1299,70,700,520
# $0 firefox 0,0,1272,1000
Last modified: Fri Jan 9 17:33:54 CET 2009
Pages by Andreas B. M. Hofmeier
An-H
email Impressum/Note Privacy
http[s]://www.abmh.de/en/papers/linux/set-window-position-geometry-from-script.html
Creative Commons License
(c) Andreas B. M. Hofmeier
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License