#!/bin/bash ACTIVE=false xscreensaver-command --watch | while read -r STATE do if condition; then command ... else command ... fi done