The Power of xdotool in X11

X11’s xdotool cli is snazzy, and solved an annoying window placement problem.

I have a set of Ubiquity Cameras that I use for basic video surveilance. I run a set of tiled windows on an older linux notebook on a corner of my desk so I can see what’s happening. VLC is great for this, and you can even tell it to restart a window if the stream fails, like this:

cvlc --loop rtsp://your.url.here &

The –loop is a neat trick. I have a bash script that starts an instance for each camera. There’s supposedly a way to do many video panes in one VLC window but I’ve not researched that.

Contrary to the VLC man page the CLI commands to position the window don’t work (–video-x and –video-y). I got tired of manually positioning the windows and finally solved it: with xdotool!

Here’s the trick:

cvlc --loop rtsp://url.to.my.cam.on.back.stairs
sleep 1
xdotool search --sync --onlyvisible --name vlc set_window --name "stairs"
win=$(xdotool search stairs)
xdotool windowmove $win 640 719

I repeated that for each camera, setting the screen positions I wanted. I have more than will fit on the screen easily and the last two windows overlap the middle ones a bit. But to “raise focus” of the windows that matter to me more I just did this:

win=$(xdotool search gate)
xdotool windowactivate $win
win=$(xdotool search inside)
xdotool windowactivate $win

Those windows are now on top.

I always knew there was a way to do this in X11 but I never dug into it before today. The xdotool is a full-on automation tool, able to send mouse and key events, watch for window events and take actions, etc. It’s the low-level primitive for creating any X11 window manager automation that you need. Very slick.

What I have not tested yet is the –loop functionality. It may respawn a new window that then is out of it’s set position (and likely has the wrong name?). I don’t know yet. What I will need is a way to detect that and then move the window to the right place again. That may be tricky and require some logic to determine which one respawned. That may need a real daemon type of application… which means I would need to integrate xdotool into an app. I wonder if it has libraries? I’ll solve that later.

For today, I’m excited I got my camera window placement automated! The power of linux.

 Share!