The trigger is exactly what you requested in your original post, and clearly shown in the code.

If you can't understand a very simple script like this I'm not sure you can be helped.