0

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?

1 Answer 1

0

You can use rcaloras' bash-preexec script to run pre-execute commands whenever the user runs something from bash. If the user enters any other shell/application, your pre-exec script will be run first, and can run its own handlers. To tell when the user exits that program, one potential solution would be to have your script continue polling in the background to see if the pid still exists.

Relevant SuperUser Answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .