toggle close/open

I want to make a script that checks if a window with a specific name exist on the current page. If exist I want to close it, else I want to open something.

I was trying something like this:

If (All (window) MatchRc (match))==true then Do {All (window) MatchRc (match) Close (window)} Else Do {Exec $[term] -n window

but this isn’t correct,
how can I do this?

By reading the following:

viewtopic.php?t=1254

– Thomas Adam