To the first shift code, under this line:

if ($istok(chat custom fserv get send,%wtype,32)) continue

add this line:

if ($window(*,%c).state == hidden) continue

*(Untested)

-genius_at_work