Hiding active window in linux

5k views Asked by At

I have written a small script to hide a Chrome window but want to modify the code to hide the active window. I can use xdotool to get the active window id and hide it. I run into problems when I want to unhide it. How do I check for a hidden window and get the id so I can unhide it? Here is my current code for just hiding chrome:

  #!/bin/bash

wid=`xdotool search --name Chrome|head -1`
wstate=`xwininfo -id $wid | grep "Map State:"`

if [[ "$wstate" == *IsViewable ]]
then
    xdotool windowunmap $wid
else
    xdotool windowmap $wid
fi
2

There are 2 answers

0
JoeJoe On BEST ANSWER

Thank you @funivan ! That got me going in the right direction. I am mapping the script to one of my mouse side buttons using xbindkeys. I changed the script a little so I can run the same command to hide or unhide a window.

#!/bin/bash

file=/tmp/last_active_window
if [[ -s $file ]] ; then
    xdotool windowmap `cat $file`
    cat /dev/null > $file
else 
    wid=`xdotool getactivewindow`      
    xdotool windowunmap $wid
    echo $wid > $file
fi
0
funivan On
#!/bin/bash

file=/tmp/last_active_window
if [[ $1 == "unhide" ]]  ; then
    xdotool windowmap `cat $file`
else 
    wid=`xdotool getactivewindow`
    xdotool windowunmap $wid
    echo $wid > $file
fi

To hide window: ./script.sh To unhide ./script.sh unhide