Is is possible to get the current context, or front-most user-facing process, to trigger a script when it changes?
For instance, the user
- starts with the command prompt,
- then goes into Emacs
- quits back into the command line
- goes into top
- quits
- etc.
For each of these transitions, can I make the terminal run a script automatically which gets the name of the new process, and potential performs an action according to the process?