Get terminal application name from shell I am used to my osascript aliases. In particular, I have nx for opening new tab and closing the old one.

However, my scripts use application name to send keyboard signals to it. Instead of writing it all many times i use my own variable term that contains terminal application name (it is always term=iTerm, no matter what terminal I'm using).

How do I fetch the terminal emulator's name I am entering command line with?
TERM_PROGRAM is set by both Terminal and iTerm:

TERM_PROGRAM=iTerm.app
TERM_PROGRAM=Apple_Terminal