From your description, you seem to require checking window titles, not necessarily program type. Here's a script that does that. It requires wmctrl
so be sure to install it with sudo apt-get intall wmctrl
Adjust the TRIGGERTITLE and the commands after if statement as needed.
#!/bin/bash
TRIGGERTITLE="enter title to search for"
while [ 1 ];do
wmctrl -lx | grep -q "$TRIGGERTITLE"
if [ $? -eq 0 ]; then
# put one or more commands of what you wanna do if the title is found
exit 1 # make sure you exit the script once the window is found, because
# it will keep on doing stuff, if sending email - it will keep spamming
# emails
fi
sleep 0.250 # delay, so that the script doesn't hoag CPU
done