How do I run a script or a program when a file system is mounted?

Hi, I would like to make an application that runs as automatically as possible. When the user inserts media such as a USB disk or a CD-ROM, and the /etc/fstab allows automatic mounting (or it is mounted automatically by some daemon), then a script or a program on that file system is run automatically.

Can this be done? I haven't seen anything like it in any of the documentation on the mount(8) command, nor has a google search produced any reasonable results.

Many thanks,