Trigging scripts from application events

is there any way to trigger a command or script whenever a certain event happens in a application like firefox.

or at least trigger a script on the launching of an application.

One way is to substitute the application with a wrapper script that does what you want and then runs the application.

hmm thanks for the idea but i want this easy to distribute so i think i would go in the direction of a timed event in the crontab first.