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.