To position a window, you can use a tool that manipulates X events such as xdotool
or wmctrl
. For example, with wmctrl
, you can use -e
:
-e <MVARG>
Resize and move a window that has been specified with a -r
action according to the <MVARG> argument.
<MVARG>
A move and resize argument has the format 'g,x,y,w,h'. All five
components are integers. The first value, g, is the gravity of
the window, with 0 being the most common value (the default
value for the window). Please see the EWMH specification for
other values.
The four remaining values are a standard geometry specification:
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.
You can usually ignore gravity, so to place a window at the top left corner of your screen and make it 1200 x 700 pixels, you would run:
wmctrl -r :ACTIVE: -e 1,1,1,1200,700
The -r
lets you select a window and :ACTIVE:
means the currently focused window.
You can also simplify your script. There is no reason to parse ps
, the special variable $!
holds the PID of the job most recently placed in the background. In any case, parsing ps
will often fail since there might be multiple processes matching Thesis.pdf
. There will always be two: the evince
and the grep Thesis.pdf
you just ran.
So, with all that in mind, you could do:
#! /bin/bash
while true; do
## Open the pdf
evince ~/doc/a.pdf &
## Save the PID of evince
pid="$!"
## Wait for a 1.5 seconds. This is to give the window time to
## appear. Change it to a higher value if your system is slower.
sleep 1.5
## Get the X name of the evince window
name=$(wmctrl -lp | awk -vpid="$pid" '$3==pid{print $1}')
## Position the window
wmctrl -ir "$name" -e 1,1,1,1200,700
## Wait
sleep 5m
## Close it
kill "$pid"
done
Note that I removed the exit 0
since, because of your while true
, it will never be reached and there's no point to it. You can play with the positional arguments to figure out where you want to place the window.
Finally, a note on DISPLAY
. This variables points to an X display. This is not a screen, it is the active X server. Many users might be running parallel X servers on a single machine, this allows you to choose which one of them a window should be displayed on. It has absolutely nothing to do with how many physical screens are connected, unless each screen is running a separate X session.
export XAUTHORITY=/home/user/.Xauthority
along withexport DISPLAY=:0.1
..then check..xrandr -q
orw
to find the display names..