Artificial intelligent assistant

How to find out if an X window is mapped (visible) or not? I use xdotool to map/unmap a set of dock-like windows. Now, xdotool doesn't come with a toggle (map/unmap) command, neither does it come with doing the same operation with multiple windows at once. So I'm trying to perform the clubbed toggle using a script. I need a way to find out if the most recent operation was a map or an unmap.

In a way, files can be thought of as a simple way to store global variables, global so that it is visible from everywhere. So the state (mapped/unmapped) can be stored as a string in a file.

Not the most elegant thing, but this script (named xctl) should do for now.


#!/usr/bin/env zsh

# This file serves as a global variable value holder showing if the windows are mapped or not.
state=/tmp/state

for process in ${@:1}; do
case $1 in
(show) xdotool search --class $process windowmap %@ windowraise %@;;
(hide) xdotool search --onlyvisible --class $process windowunmap %@;;
(*) break;;
esac
done

[[ $1 == toggle ]] && {
[[ -f $state ]] && [[ `cat $state` == show ]] && xctl hide ${@:1} || xctl show ${@:1}
} || echo $1 > $state


To toggle a set of windows, run `xctl toggle window1 window2 ...`.

The script must reside in the shell's path.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 3d7c945b63cb9e9f84f0a0f8a054930c